Homeless Bob Initiative
Yes, but it might be considered a little creative to say the least. John only has to change Bob's job description from waiter to night watchman and pay him for the eight hours he is on duty at night while the establishment is closed. There is no law that prevents an employee from nodding off while he is on the clock. It's strictly a matter between the employer and the employee. For fun, John could provide security cop uniform pajamas (widely available online) and a comfortable couch in the break room.
During the day, Bob could act as a volunteer to perform his regular duties of waiting on tables. This makes it possible for him to be covered by insurance while he is on the premises at any hour. The added benefit of having a watchman available might even lead to lower insurance rates due to the lower risk and/or prevention of robberies and fire.
I've seen this done on construction sites and it greatly reduces losses of construction materials. It's very effective and helpful to everyone all around. It's very common for night watchmen to be allowed to engage in other activities while they remain at their post, even if snoozing isn't specifically mentioned.
In the UK, employers cannot legally force employees to work longer than their contracted hours, but no law prevents workers from choosing to stay on the premises if the employer allows it. There needs to be no contract at all for this arrangement.
There are no laws in the UK that define the rights of volunteers or the legal definition of a volunteer. A person who is paid for his shift as a night watchman can volunteer to wait tables during the day. Employees are entitled to at least 11 hours of consecutive rest in every 24-hour period, but they are not forced to rest and they are not prevented from 'lending a hand' if they wish to during their off hours. Labor laws are designed to prevent employers from abusing their workers, but no law prevents them from being kind, generous, flexible, and charitable.
As long as John and Bob are okay with the deal, no one else has any say in the matter. Even if the locals did find out about it, they would most likely admire John and be glad that Bob wasn't sleeping under the bridge. No judge could prevent it unless it came into a court of law.
This legal strategy is based on maintaining a non-adversarial relationship between two parties. No lawyer would recommend it for obvious reasons: 1) the high probability that it would become adversarial, and 2) the lack of recourse for either party if it did. The question asks if there is a legal way for Homeless Bob to remain on the premises in a non-residential facility as a non-resident. This is one possible way, regardless of the probability of a poor outcome.
In practice, this situation is more often handled in the manner that @Perkins suggests in his comment on the question: "If the employer has plausible deniability that they knew the employee tasked with closing up was staying the night, then it's just a matter of making sure nothing ever happens that would require said employer to officially take notice."
In my own personal experience, I've purchased abandoned homes that were far below residential standards, and I am like John in the OP's question in the sense that "John would like to help". My Homeless Bob is retired on a low fixed income and wants to occupy and purchase a home, but cannot afford a down payment and cannot get a loan. To avoid liability, I am free to transfer ownership free and clear "as is" and rely on his word that he will make payments as he can going forward.
No one, especially not a lawyer, would advise me to do so. Bob could decide to pay nothing and get a free house. It's madness. It's crazy and it's not advised, but it's legal. I have to wonder if this is more insane or less insane than enormous masses of humans clutching and scratching at each other's eyes to 'get over' on one another.
One important advantage is that this makes Trust and Honor possible by allowing space for trustworthiness and honor to flourish. Banks, lawyers, and real estate agents get completely cut out of the deal and are no longer able to prey on us. The 'Homeless Bob Initiative' is also known as "Occupy This!"