The defense of insanity is an affirmative defense that exculpates the defendant from any criminal liability because, at the time of the crime, the person did not appreciate the nature, quality, or wrongfulness of his actions.
A defendant who claims defense by reason of insanity normally must undergo a psychological examination before putting forth the defense.
Use of the insanity defense tends to be rare and sustaining the defense at trial is very difficult. Putting forth an insanity defense might be said to be equivalent to pleading ‘not guilty by reason of insanity’ which, if successful, will result in the defendant being committed to a psychiatric institution instead of prison for an indeterminate period.
Many jurisdictions allow for a defense by diminished capacity, which serves as a mitigating factor to reduce charges or sentences.
Allowing an insanity defense is based on the theory that conviction and punishment are justified only if the defendant deserves them, and it would be unfair to punish someone who is so mentally disturbed that he lacks responsibility as a moral agent. The legal definition of insanity is very different from the psychiatric definitions of mental illness and should not be used interchangeably.
The insanity defense has historical roots in common law dating back to 13th Century England when “complete madness” was established as a defense to criminal charges.
The test evolved over time and by the 18th Century had evolved into the “wild beast” test, wherein a person deprived of his understanding and memory so as not to be any more aware of his actions than a wild beast could be excused from criminal liability for his conduct.[
WIKIPEDIA
http://defensewiki.ibj.org/index.php/Insanity_Defense
VIDEO