I think that most perpetrators of violent crime have some degree of insanity. The key to reducing crime is identifying the "seeds" of criminal behavior, and treating it as early as possible. Also, sociopaths cannot be reasoned with, nor is punishment effective. Some people need to be put out of their misery. No amount of "rehabilitation" will help some people.
“In politics, stupidity is not a handicap.” -Napoleon
First off, despite the way courtroom dramas portray it the insanity defense very, very, rarely used, and works even less than that. Only about 1% of cases does the defendant raise the insanity defense and it only works in something like 0.05% of cases. So, just keep that in mind. Generally it is only successful when the defendant is really far around the bend and has decades of medical history proving it.
That said, I do have many problems with it.
1) It isn't necessarily a win for the defendant. Criminal mental health facilities are just like, or potentially even worse than, prisons. And, in theory, you are held there until you are cured. There are many situations where a person is arrested for a minor crime- say petty theft- and deemed incompetent to stand trial. Then they are put in a criminal mental health facility. Where petty theft might have only incurred a fine and probation, or maybe a week in jail, they are kept there until they are deemed to be cured, which can be years or even their entire lives. Many respectable lawyers will not raise the insanity defense even if they know they would win it because of this. A lot of cases where it is raised the lawyer is actually trying to game the system. They want to be able to record the case as a "win" and are willing to send their client up the river to do it.
2) It is almost impossible to define insanity in a way that a jury can weigh. So it ends up being applied arbitrarily. For example, "unable to tell the difference between right and wrong" only encompasses a very small slice of insanity and often times does not cover some of the most severe and debilitating conditions.
3) It is hard to justify how it wouldn't apply to everybody that commits really heinous crimes. Somebody who would kill and torture a child for no reason, for example, is clearly insane, but we still want to punish them. So we end up with arbitrary decisions. It isn't a principled distinction.
But, the catch is, I don't know what would be a better solution. If a severely mentally handicapped person steals something from a store because he literally didn't know that it didn't belong to him or even what that means, that isn't really the same thing as somebody who consciously chooses to commit theft. That person does need treatment and doesn't deserve punishment. Part of it comes down to conflicting ideas of the purpose of the law. Is it simply a mechanism for moral retribution for its own sake? Is it to rehabilitate people? It is to simply lock people up so they can't commit crimes while they're locked up? You get different answers about how to handle insanity depending on which philosophy you subscribe too. Probably really it should be a mix of all three approaches.
People will resort to vigilante justice if justice is not being done. I am sure most people want a justice system where a unbiased 3rd party hears both sides and passes judgement, however if that unbiased 3rd party does not do its job then this creates a distrust in the ability of that unbiased to adequately do its job.Vigilante justice has a much poorer track record of meting out justice to those who deserve it and not harming the innocent than courts.
"A nation can survive its fools, and even the ambitious. But it cannot survive treason from within. An enemy at the gates is less formidable, for he is known and carries his banner openly. But the traitor moves amongst those within the gate freely, his sly whispers rustling through all the alleys, heard in the very halls of government itself. For the traitor appears not a traitor; he speaks in accents familiar to his victims, and he wears their face and their arguments, he appeals to the baseness that lies deep in the hearts of all men. He rots the soul of a nation, he works secretly and unknown in the night to undermine the pillars of the city, he infects the body politic so that it can no longer resist. A murder is less to fear"
Cicero Marcus Tullius