There has not been a great deal of research on this topic but from what is available it appears that the urge for a dog to eat their stool comes from ancient dogs doing so in the den in order to protect other dogs in the den from the parasites in the stool.
So, the origins are of a protective nature...they're cleaning up!
The practice is more common in situations where there is more than one dog in the home. As well, females tend to have a higher percentage of this behaviour than males. For the most part dogs who do this prefer fresh, or under 2 day old poop.
If your dog does this then there are numerous ways you can deter them. First keep your dog's living area clean. Second supervise them on walks closely. If they poop, clean it up and don't let them eat it. Training commands of "leave it" or "come" will work if your dog has been trained and you see them getting ready to eat some. When I get asked "why does my dog eat its poop?" I tell my clients they eat their poop because you let them. Again, train don't complain!
If you are unable to train them to leave it, a few cases have shown success in supplementing with vitamin B or supplementing with an enzyme called papain. The final step would be to get some spray that you could spray onto the poop that would deter them from eating it, however if you are going to go through all that trouble and expense, it would just be easier to clean it up.