What's the benefit in keeping three year old milk? There is no way a malicious government or supermarket can keep that up, at some point they are going to run out of storage.
The other reason is that expired food is often still edible but not legal to sell and these programs are about reducing waste, not about giving free food to the homeless. If you give fresh food away what are you going to do about the waste?
If you think this is some conspiracy against the homeless you should remember that many countries have unemployment or low income benefits that also apply to homeless people which give them the ability to buy food.