Legal insanity is not the same as medical insanity. The test is simple - was the person capable of understanding that his actions were wrong?
Motive doesn't come into play unless we're talking about a criminal offence, which necessarily must have mens rea
- a "guilty mind" (this concept underlies things like intent and motive). Someone detained for psychiatric treatment by virtue of the insanity defence isn't convicted of a criminal offence; by definition, he cannot possess mens rea
and so cannot be guilty of a crime.
My opinion is that Breivik shouldn't be eligible for legal insanity. He clearly had strong notions about right and wrong, and clearly understood that harming children was wrong.
I confess I am sort of hoping he doesn't survive long in jail.