Avoiding criminal prosecution on the basis of "insanity" is not as common as many people might think. This article discusses this rarely successful defense.
Read: http://northernpublicradio.org/post/niu-professor-calls-insanity-ruling-rockford-murder-case-rare