We don’t really know, or at least no theory has gained general acceptance concerning the ritual killing and burial of sacred animals. “A truly satisfying explanation for this is lacking,” writes one scholar (Quack 2007, 37), while another notes that “the basis of animal cults is not totally clear” (Ikram 2012, 6).
First, chronological scope: evidence for the practice of mummifying animals in large numbers proliferates in the Late and Greco-Roman periods. A nice example of this development is the enlargement and adaptation of part of a New Kingdom official’s tomb (TT 11, ca. 1470 BCE) to create catacombs for animal mummies, a renovation that took place in the second century BCE. The famed Ibis Burial Ground of Tuna al-Gabal seems to have been founded under Psametik I (664-610 BCE) and was greatly expanded in the Ptolemaic period. An estimated million ibises were eventually buried along with other animals in this massive subterranean complex.
Given the large number of animals involved and physical evidence, it is clear that most of these and other mummified animals were purposefully killed. Yet, as you note, there were clear prohibitions and penalties associated with the maltreatment of sacred animals, which are reflected in the accounts of the Greek writers Herodotus (II.65-67) and Diodorus Siculus (I.83 ff.), both of whom visited Egypt, but also in Egyptian texts, such as a second-century CE Demotic papyrus: “Do not beat any (sacred) animals with a stick, stone, or any (piece of) wood. Be careful with regard to the animals which are sacred” (P. Ashmolean Dem. 1984.77 verso).
So, what gives? The phrase “sacred animals,” used both in ancient sources and modern literature, masks a variety of situations. Certain animals, such as the famed Apis bull, were considered actual manifestations of the divine; their natural deaths prompted a period of mourning and search for the next divine manifestation, who could be recognized by certain markings. Other animals were associated with divinities (for instance, cats with Bastet and the sun god Re) but were not actual manifestations of these gods. This association gave them a special status, which protected them from non-ritual abuse, but also rendered them attractive conduits to the gods: the ritually buried animal could serve as a votive offering, opening up communication between the dedicator and the divine.
Of crucial importance, it seems, was the context of the animal’s death and the status of the person involved, particular whether they were a recognized practitioner of sacred rites or not. Even an accidental killing could bring a swift penalty, at least according to Greek sources: Diodorus Siculus, for instance, claims to have witnessed the lynching of a Roman who accidentally killed a cat. “Because of their fear of such a punishment,” Diodorus relates, “any who have caught sight of one of these animals lying dead withdraw to a great distance and shout with lamentations and protestations that they found the animal already dead” (I.83).
Interestingly, this picture is corroborated by a petition on papyrus dating to 202 or 178 BCE (P.Köln XV 594). The petitioner is an embalmer named Onnophris, who found kittens in his house abandoned by their mother. While weaning them with milk, a tomcat snatched the kittens away, and Onnophris was only able to recover one of them, which he then delivered to the local priests of Bastet. He can produce the village scribe as a witness, and the petition serves as a record of his actions, which he hopes will protect him from malicious accusations that he had caused the death of sacred kittens.
Note that Onnophris brings the surviving kitten to the priests of Bastet, who are the appropriate sacred practitioners in this case. Already Herodotus records appointed “guardians” of sacred animals, which are inherited posts, similar to the animal “feeders” and “buriers” recorded in papyri from later periods. They were likely the individuals who were sanctioned (whether by custom or law I do not know) to kill and ritually bury sacred animals for their clients. Often these ritual practitioners used parts of different animals or non-animal remains in their mummies, although whether this was deception or accepted practice is unclear.
Further Reading and Sources
Helpful responses on this forum include those of u/lucaslavia responding to the idea of "cat worship" (In ancient Egypt, they worshipped cats. What was the cat population in Egypt? Were all of them worshipped?) and u/cleopatra_philopater on outsiders' views of Egyptian practices regarding sacred animals (Cats held a special place in Egyptian society. What were the views of other Mediterranean cultures on this practice?).
J. Cromwell and L. Prada, “Kittens for Bastet,” Papyrus Stories. Everyday Stories from the Ancient Past. https://papyrus-stories.com/2020/04/13/kittens-for-bastet.
R. Daniel, “Petition Concerning Kittens,” P.Köln XV 594.
S. Ikram, Divine Creatures: Animal Mummies in Ancient Egypt (Cairo 2012).
J.F. Quack, “Tier des Sonnengottes und Schlangenbekämpfer Zur Theologie der Katze im Alten Ägypten,” in R. Kampling (ed.), Eine seltsame Gefährtin. Katzen, Religion, Theologie und Theologen (Frankfurt 2007), 11-39. PDF here