In Arizona one now can be found guilty but insane. This results in confinement in a mental institution for treatment. When deemed no longer insane, the sentence for conviction is finished in prison. This change in the law was a result of a man who murdered his wife but plead insanity. The jury found him insane and he went to a mental institution. A few months later, he was declared no longer insane and released. He basically got off scot-free for murdering his wife.
AZ law also provides for psych evaluation pre-trial with mandatory treatment if necessary. If rehabilitation is not possible, permanent confinement in a mental institution can be ordered.
These processes keep dangerous wackos off the street until their trial is settled