Hot foods are supposed to be kept at a certain temperature, and cold foods likewise. If they are donated and taken off the premises without temp. controls, the fear is the foods could be contaminated or spoiled before they are eaten. Then who would be responsible for people in a homeless shelter getting sick from it - the original restaurant, the transporters, the shelter for serving it?
No one wants to open that can o' worms, so as a result, food gets wasted.
Sometimes I think we worry too much, but I have known personally of one large picnic where food, including stuff like egg salad made with mayonnaise, was sitting out for a long time in the heat, and nearly everyone (more than 50 people) got sick from it. People who didn't eat that egg salad were fine.
I had a bad case of food poisoning myself once (different incident) and was SO sick for 4 days, I lost 10 lbs. and became quite dehydrated.
So...probably better to be safe with food handling than to take chances on it.
Edited to add: I'm talking here about not donating food from buffets, since that was the conversation at the time. Restaurants that have left-over food that has not been sitting out are in a different situation.