Of course it had something to do with religion, but that may not have been the primary motivator. Humans are a crazy mix of beliefs. Maybe his religion played a part, a movie he loved played a part, he was depressed and on drugs, he was a member of some website with strange beliefs, or maybe he was an admirer of ISIS.
Could be a mix of all of the above as well as a million other things.
But what he did have was an automatic weapon that could kill and injure 100 people.
There are a lot of evil people that would love to get their hands on nukes. The reason we haven't had a nuclear war is that it's incredibly difficult to get a nuclear weapon.
As long as automatic weapons are easy to get, these type of events will happen from time to time when people snap.