Insanity pleas are notorious because they are often dramatized in television shows and movies. In the real world, they are very difficult to prove.
There are two things you should understand about an insanity plea, and these things are often confused. Before there is a trial, the judge will need to determine whether or not you are fit to stand trial. That requires that you understand the charges against you and are able to participate in your own defense. If you cannot face your charges, you are remanded to the care of a psychiatric facility until they stabilize you enough so that you can stand trial for the crimes with which you are charged.
That is completely different from an insanity plea. If you plead insanity, the judge has already ruled that you can stand trial for your crime, but as a defense, you are saying you were not in your right mind when you committed the offense and should, therefore, not be held responsible for it. It is very difficult to prove because the criteria for proof is very high. Sometimes, it works.