Is it wrong for the homeless to sleep in your house in the room no one is currently using?
The restaurants have to pay to replace food the homeless would pick up during the day (or even put in work to prepare it for a restaurant). Food that's leftover at the end of the day and can't be sold the next day could certainly be given to the homeless for free (and I know of at least a few restaurants in my city that do this).
The homeless person sleeping in the spare room creates cleanup work, and prevents you from using that room at a moment's notice. If a homeless person could sleep in my spare room without using the shared spaces and leaving the room instantly, in perfect order, the moment I wanted to use the room, I don't think I can morally justify not letting them.
So while the situations you mention may or may not be moral, it's shifting the debate back into a worldview centred around scarcity.
And the fact that they can't afford it gives them justification for stealing it? Would it not make more sense, that if you can't afford something you aren't entitled to it? If a poor or homeless person were to steal food from a shop they wouldn't be allowed to do it because, although they would like to pay, it isn't possible for them to do so.