The Americans have a provision in law that allows them to institutionalize someone they regard as being ill in this way for as long as they like
The UK used to have 'Lunatic Asylums' which were closed down in favour of 'Care in the Community' - Bad idea.
For the 'Halfway house' types we also once had a large Merchant Navy and military which absorbed people who could function in an institution with other males to 'guide'* them but who are 'difficult'** in polite society.
* Respond in kind if they kicked off.
** PITA.