In the wild, if you poo where your sleep, predators find you. Adult animals know better, and defecate far away from their sleeping areas. Younger animals do not know any better and poo where they stand. Since mom and dad don't have pooper-scoopers and hands to pick up the poo, they eat it and it eventually gets where it needs to be, safely far away.
The instinct sticks with domesticated dogs, and once they learn that predators aren't trying to break into your backyard to eat them, they'll stop the behavior.