Dogs seem to eat feces for many reasons, such as poor digestion, hunger, boredom, stress, curiosity, seeing mom do it when cleaning up after her litter, getting attention, or avoiding punishment by hiding “accidents”.
I'm not sure how eating one's own feces would affect the microbiome but Coprophagia is not unusual for many different species. Without a ruminant's multi-chambered digestive system (see: cattle, deer), animals like rabbits actually have to eat once digested food in order to extract the full nutrients from hard to digest grass and plant matter.
Evolution only optimizes for having offspring in the future. Trying to find a rational reason for some evolved behavior is not necessarily a fruitful way to think about it.
How can you tell that they lack nutrients? I have a basset hound and despite his supposedly excellent sense of smell he still enjoys "chocolate" snacks on a regular basis. He's an adult dog and getting Kirkland food. His weight is consistent and the vet is happy about what he weighs. I would love to be proven wrong (please!) but I doubt he's "snacking" because he lacks nutrients. I think he might be a little slow mentally and maybe he's _that_ hungry and doesn't have access to anything else to eat.