There aren't enough houses where people want to live. There are plenty of dirt cheap houses in rural nowhere with no jobs within a four hour drive. There are plenty of empty second homes in developments with no access to any public transit or services that would be unlivable to poor people even if we gave them the houses for free. There are few enough empty units in New York and the like that the owners reasonably believe they can, with patience and strategy, rent them out or sell for a profit.
A significant chunk of homeless people, the "chronically homeless", have the challenges you referenced and are difficult to support into stable housing. But the majority of homeless people, the "transiently homeless", are just poor and had one too many hard knocks to be able to hold onto their housing unit. With the high cost of housing - driven by unit shortage where they live - being one of those knocks.