This begs the question: what is the difference between competency to stand trial and the insanity defense? There are three basic differences:
The first difference is the timeframe considered. Determining someone’s competency to stand trial is concerned with their mental state at the time of legal proceedings and trial. Whether a person can be found not guilty by reason of insanity is determined by looking at the person’s mental state at the time the crime was committed. So, competency is concerned with today, whereas insanity is concerned with a distinct point in the past.
The second difference is the standard. Competency is determined by whether the defendant can understand the nature and consequences of the criminal proceedings against him and whether he can assist in his defense.
The insanity defense varies greatly from state to state. Federal courts use the M'Naghten test to determine if someone is legally insane. The M'Naghten test generally asks whether the defendant, because of a defect of reason, either did not understand the nature and quality of his acts or did not know that his acts were wrong. (Check out this post for more about the insanity defense and the M'Naghten test.)
The third difference is procedural. Competency is determined by the judge, and must be considered before a trial can take place. If found incompetent, the defendant is treated in a mental facility and is periodically evaluated to determine whether he has gained competence.
Insanity is determined by the jury (assuming the defendant has a jury trial). It is a complete defense to the crime charged. The idea is that if a person was insane at the time the crime was committed, he or she is excused from responsibility for the crime, and must be found not guilty. However, being found not guilty by reason of insanity does not mean he goes free. Generally, the person found legally insane can be locked up in a mental facility until doctors determine he or she is safe to return to society.
For more on the insanity defense, check out this post.