If you go to a mental hospital, you can't leave. If someone does something to harm you- whether it's "assault" or "wrong meds"- you still can't leave, you are locked up with them. Is there a place that is kind of like a mental hospital, but you can leave? A monastery? A crisis center? Some sort of treatment program?
I know that in my area at least, if you admit yourself into inpatient mental health treatment you can check yourself out of there when you want, unless you do something like try to hurt yourself, and then they can hold you there until they feel you're okay to leave on your own
Tentatively I agree with @Everett, if that's how the law works where you are, but exercise caution -- psych wards can be really scary places, mostly not because of the crazy people. (Source: have experienced various fuckery in multiple psych wards, 90% of which was from staff; know other people who have been treated similarly; do not think that merely having a different legal status would have protected any of us much.) Ideally you'd want to go to a place that you know someone who went to. Failing that try to find some kind of testimonial online. People might be biased or even delusional, but there's a big difference between "I'm conflicted, I'm not sure I should have been institutionalized and it wasn't fun" and credible allegations of human rights violations like Spoiler: not graphic but still maybe disturbing "I was held there for a week with no access to a phone" or "they wake us up at 6am and force us to pray" or "as far as I'm aware the staff member who sexually abused me is still working there."
I'd look into intensive outpatient programs. I had a lot of success with that as a way to jumpstart my treatment when my symptoms were at their worst. You get a lot of group therapy and programming but you can in fact leave, and do every day.