Most states right now allow a person who has been committed to waive a right provided by law. A waiver is the act of intentionally relinquishing or abandoning a known right, claim, or privilege.
To be committed the person must be found to be suffering from a mental illness (there are other grounds too, like alcoholism) and a danger to himself, others and/or property.
So, the committed person is not deemed well enough to decide to leave the institution if his/her doctor disagrees, but is deemed well enough to waive a hearing on his/her involuntary confinement. How truly bizarre and illogical.
If, for the sake of argument, compassionate euthanasia for some mental illnesses is considered appropriate, a guardian or other fiduciary likely would have to begin the process, the mentally ill person deemed to be lacking the capacity to do so. I envision protracted proceedings akin to what goes on in death penalty cases.