Can we all calm down and look at this rationally. Why is it that we have to stretch for outlandish theories and pop psychology answers? Occam's Razor -  Among competing hypotheses, the one with the fewest assumptions should be selected.

The guy was casing the community and the club in anticipation of this attack. He wasn't a crazed madman or a closeted gay. He was a radicalized Muslim extremist with an agenda not unlike the Paris shooters last winter. ISIS accepted responsibility early. They didn't do that with San Bernardino, so there's probably a connection to this one. Radicalized Muslim extremists go to mosque. There could be thousands of ISIS operatives hanging out in American mosques, both home-grown and those that slipped across our very porous borders.  Just because ISIS is good at social media doesn't mean they don't also use more old school techniques like friendship at the mosque, the coffee shop, the book store, work .... 

That is the simplest hypothesis.