A lack of mental health services is one factor that contributes to homelessness. A disproportionate number of homeless people are mentally ill, which provides, at the very least, correlation, if not causation. But there are many reasons to think there is a causal relationship. Mental illnesses, left untreated, can cause people to not be able to work, for example, thus leading to a lack of income and the wherewithal to pay for housing. Mental illnesses often interfere with normal and logical thought processes, leading people to make poor decisions that can result in homelessness. Some mental illnesses, schizophrenia, for example, can cause delusions and paranoia that render those who have it unable to engage in the day to day transactions that are a necessity to acquire or keep housing, paying rent or living cleanly and quietly. Some untreated mentally ill people who originally lived with their families are unable to stay with their families because they are not tolerated very well, no matter how much they might be loved. Social skills often go by the wayside, and some families simply cannot deal with the mental illness of a parent, child, sibling, or spouse. Additionally, untreated mental illness frequently leads to drug and alcohol abuse, which creates a situation in which the mentally ill person, trying to self-medicate, might use all of his or her income on drugs or alcohol, creating a situation in which rent cannot be paid, or creating behavior that other people find they cannot live with, thus creating homelessness.
As a historic footnote to all of this, it should be pointed out that many years ago, in the late 1960s and early 1970s, there was a movement to de-institutionalize many mentally ill people who really did not need institutionalization, simply some support on the outside, but that when these people were "set free," there was inadequate support in their communities, not enough mental health treatment, not enough social workers, and so on. I am not really sure about the statistics on this, but it is my educated guess that this led to a dramatic increase in homelessness among the mentally ill. Since there is still inadequate support for the mentally ill, this sad situation is still with us.