It’s technically possible to do that after committing any crime, but under super specific circumstances and it’s a far cry from a “get out of jail free” card.
If you’re legitimately, actually insane when you commit a crime you’ll get sent to a mental hospital instead of prison. The catch is that the hospital will only release you if you’re mentally healthy. That can mean that a person who uses the insanity plea may spend more time in the hospital than they would have in prison.