The 'lunatics' are angry young men. They pop up whenever there is economic injustice. That's why Egypt, Libya, Syria, and Greece are burning right now. When conditions are bad, the young men snap. It's a human trait; hell, it's a primate trait. You see the same incidents in chimpanzee tribes that don't treat their young males well, although of course chimps don't own guns.
There are three angles by which you can attack this problem:
Make society prosperous enough that no one becomes angry at it. That's unrealistic.
Monitor, jail, and either kill or treat all people with a hint of mental problems. In bad economic times, that will mean imprisoning a large fraction of your male population.
Eliminate guns. Determined lunatics will use bombs or knives, but it can be more difficult to kill people in mass that way, especially on a sudden impulse.