I truly don't understand how this is legal. They can just call someone "too" mentally ill and lock them up?
Yes. Thats how it worked for over 100 years in the US, until the 1980s. I remember being shocked to learn this too, being too young to remember such a time. The “funny farm” was a real place.
But the alternative is what we have now. Where every major city in the country has thousands of deranged psychotic people roaming the streets, completely unmedicated or cared for, until they inevitably cause harm to themselves or someone else.