I think you’re making two assumptions that I doubt.
1) That people with mental illness cannot keep themselves housed assuming housing is available and affordable.
2) That the seemingly high prevalence of mental illness is a cause of homelessness, rather than a symptom.
I don’t think either of those is entirely true.