Yes, it should be legal to take food thrown out by supermarkets, because people do not have a legal right to things that they throw away. The supermarket should not have any liability for food that is not good anymore, because the people who take the food choose to eat it. But it is better that the food is used than it is left to waste.
In the famous words of John Locke, people have the right to life, liberty, and property, and the government has the obligation to protect these things. If a supermarket throws something out, it is willfully giving up their property, and they, therefore, have no right to tell people they can't have it.
It should be legal to take food that is thrown out by supermarkets because that food would otherwise go to waste. Tones of food is wasted and thrown away that would be otherwise suitable for eating. With all of the starving people in the world, we should not be throwing food away.
Supermarkets should be donating food rather than throwing it out in the first place. If they are not donating it, then it is public domain. Anyone that wants it can take it. It is sad to see how much food we waste. Most of it is perfectly good food and homeless people, or low-income people would be glad to have it.
While the food thrown out by grocery stores may still be edible, there is no guarantee that it is safe to consume... and if the discarded food is in fact safe to consume, it should be donated to a charitable organization rather than left out for dumpster divers to pick through.