Homelessness can happen to hard workers who get laid off due to cost cuts. It can happen to veterans who served our nation but can't get a job afterwards. It can even happen to rich and successful individuals who lose everything to natural disaster.
The reason why no one deserves homelessness is because they lose not only the basic resources to survive, but they may also lose hope in trying to become productive citizens. This causes many to unfortunately turn to drugs or crime, becoming problematic for the rest of society.
You don't necessarily need to get rid of capitalism to solve the homelessness crisis. You can have a system of universal basic income, in which everyone is given enough money for their needs but still has to have a career to earn money for their wants.
Elon Musk proposed this as a way to prevent people from facing financial struggle as AI increasingly replaces jobs. Now that he's more right-wing, he might not make it as a welfare system but rather as stimulus checks, possibly with the revenue recaptured using DOGE.