There are differing views on just HOW insane the Joker is (Jason speculated in Under the hood that he's not nearly as nuts as he claims, but Chuck Dixon had him be literally brain damaged and thus be irredeemably insane). Howeverm I didn't say he wasn't insane, but he's not legally insane because he understands perfectly what he's doing.
Generally, to be legally insane you have to have had no concept that what you were doing was criminal or dangerous. That shooting a gun at someone wouldn't kill them because, as God, you KNEW with absolute conviction that you would transform the bullets into daisies before it hit them.
The Joker knows full well that he's killing people in gruesome and grotesque ways, he just doesn't care that it's illegal, immoral and sick, he just finds it funny.