I think the best way of it to look at how it works is this:
Suicide is not illegal and you technically have the freedom to do it as an individual; that said if you *want* to kill yourself you're in a mentally unstable state, therefore you're not of sound mind therefore you are unable to make your own important decisions therefore you should be hospitalized to be made of sound mind again. It's not impermissible; there's no punishment. It mandates treatment however.
Catch 22. I don't necessarily agree with it (I think it can certainly be true often though) but I think that's the best way to consider the way it's legally considered.