Then why on earth can't my dog distinguish dog-crap from real food, and spoiled, rotten food from things that are ok to eat?
He probably can, but doesn't care.
Also, dogs sometimes like
spoiled and rotten things. I was even once told that giving a dog a piece of slightly rotten meat every month or few is healthy because it helps to balance something in the digestive system.
As for crap, I'm afraid your dog is just 'one of those' who do it. :)