Legal standards surround the process by which those who are mentally ill can be forced, against their will, to receive treatment. Statutes for involuntary commitment whether denominated civil or criminal are subject to the due process clause of the 14th Amendment. This is because involuntary commitment severly infringes on a person's right to be free from governmental restraint and the right to not be confined unnecessarily. Courts have held that such statutes must bear some reasonable relation to the purpose for which the individual is committed.
Finally and most conspicuously, the criminal justice system has, of necessity, to address issues of responsibility, appropriateness of trial and treatment in the light of mental health considerations.
States dictate how and when the insanity defense may be invoked in state court while the federal government does so for the federal court system. In 1984, the Insanity Defense Reform Act (18 U.S.C. 17) was passed. Generally, it placed the burden of proving insanity on the defendant and it cut on the use of mental illness as a defense. Today, insanity is rarely invoked and of those, only a quarter succeed.
[excerpted from the Cornell Law website]