The short answer is it depends.
In order to be prosecuted for a criminal offense, a person must be competent to stand trial.
Competency is determined by a medical evaluation performed by a Doctor at the direction of the Court.
A finding of incompetence may result in hospitalization until someone is able to regain competency, a mental commitment or dismissal of a case.
It is important to have an attorney who understands the complexity of mental illness and can navigate the court system to provide the best possible defense.