Looking at SF specifically, the causes seem to be "job loss (26%), alcohol/drug use (18%), eviction (13%), argument/asked to leave by friend/family (12%), mental health issues (8%), and divorce/separation (5%)".
One thing that seemed to have worked in London a few years ago is to give people a bank account with £3,000 with no strings or obligations attached.[1] While the pilot was small (13 people) and time period relatively short (1 year), the results were promising. I seem to recall it's been tried elsewhere too, but I can't find the report on that right now.
Turns out that just giving people a chance and autonomy goes a long way. Unfortunately "free money for homeless people" is politically difficult, even though the alternative is far more expensive.
[1]: https://www.jrf.org.uk/report/providing-personalised-support...