Back in the 70's and prior, mental health facilities were barbaric. "One Flew Over the Cuckoo's Nest" brought to light these travesties, and many were shut down.
Later, republicans then shut down more by defunding as well. What effectively happens is people are shunted to other communities where better services are offered. Lookup "Greyhound therapy", where city govt's pay for bus service to 'somewhere else'.
Now, the primary caregiver is the penal system. And remember, we still do not have single-payer medical, so unemployed/homeless are still without.
Robert Kennedy even spoke spoke out in public against the facility (his sister suffered a bad lobotomy requiring full time care). Many kinds of institutions closed in the 1970's, and for good reasons.
With that said though, mentally ill homeless can be a challenging problem. Many of these ill "fell through the cracks", and even if a program was offered for them, they don't have the capability to seek out said program.
Mental health is a definite dark spot in America.
And it's not necessary a factory. It's not hard to create awful work environments.