Just as we may bury a favorite animal because that is what we do when a person dies, the Egyptians mummified their favorite pets because that is what they did when a person died.
Some animals were considered sacred to particular gods: cats to Bastet and ibises to Thoth, for example. These animals were mummified when they died and the mummies were often placed in the gods' temples.