Coprohagia is the technical term for eating feces. This has been studied in dogs by several people with no definitive answer for "why" being found.

Nutritional deficiencies may be present in some dogs, but not very many. This may be boredom related in many dogs. It has some "natural" roots in the fact that dams often eat their pup's stools, apparently as a method of hiding their presence from predators. Dogs will eat the stools of other species, especially cats and rabbits, too. Dogs obviously do not find the taste of feces objectionable or the behavior would be self correcting. So I think of this as a natural behavior that upsets people. Since dogs have to live with people, it is becomes an issue. There is a product sold that is supposed to help with this habit -- Forbid. It doesn't work in all cases (it might not even work in most cases). Another alternative is putting meat tenderizer in the dog's food. This works for some dogs. Walking a dog on a leash and working hard to keep it from turning and eating its stool is helpful. It is sometimes possible to distract the dog by running a short distance after the dog has a bowel movement or by taking a couple of rapid steps then telling the dog to "sit" and giving it a treat. These behaviors may stay on as substitutes to eating the stool. If you can keep the dog from eating stool for a month or so it is sometimes long enough to break the habit. Picking up stool to prevent its ingestion works in dogs that don't quickly eat their own stool but do so when put in the yard alone. "Booby trapping" a sample of stool by cutting it in half lengthwise, and putting some Tabasco type sauce on the inside of the stool, then putting it back together so that the dog is not aware of the hot sauce until it eats the stool can help in some cases. This can be a hard habit to break.