Why does an animal eat feces?

There are many reasons why some animals consume feces. An animal may eat their feces for the following reasons:

- it is a part of their normal digestive pattern.
Some species do what is called Post Gastric Digestion, in which bacteria in their large intestine digest the components of the food that the animal cannot digest itself (such as cellulose/fiber), and convert that material into proteins (incorporated into the cells of the bacteria as they grow), which the animal could digest, if it could get a hold of them. The easy way to do that is to extract the bacteria and eat them.
Rabbits are a common example of a species which is designed to utilize this extra protein source, and routinely eat their own feces, even in the wild.

- the animal is lacking in a particular nutrient.
Some nutrients are difficult to absorb in the digestive system, even if it is only present in small amounts. This means that a lot of a hard-to-absorb nutrient which goes into its mouth in its food is still left when the food gets to the back end of the animal. If an animal is lacking in that nutrient, it may reconsume its feces to get a second shot at absorbing the nutrient.

- stress, obsessive behavior, or other psychological causes.
The exact mechanism that leads to psychologically-induced coprophagia (eating of feces) is hard to pin down universally. Some instances may be the result of stress, or conditioning, or other forms of mental illness.

- pathogenic illness.
Some diseases can cause behavioral and mental changes that lead to abnormal behaviors, such as a change in what the animal defines as acceptable food, which can lead to coprophagia.