sacwe can disagree on the reasons why and what would have prevented it, but it's no secret that ISIS really loves murdering gay people.
The wider social context around gun control can't deal with individuals like these. They live apparently law abiding blameless lives of conformity until exploding. No one would deny them gun ownership on any simple clearly assessable criteria.
The best scholarly work I've seen done on the psychology of Islamist (and in general right wing) extremists identifies 4 particular personality traits that are key to the individual's motivation:
Disgust - a notion of purity or cleanliness taken to an extreme degree, it could be nationalist or racial for some right wing extremists but in Islamist cases they are noted for a hatred of homosexuality in particular and extreme sexism
Need for Closure - a preference for order, structure and certainties, and a rejection of ambiguities, which obviously leads into a strong preference for authoritarianism. Essentially they want to see the world as a simple story.
In/out group distinction - a very clear perception of a sharp distinction of being or not being in a particular group, which produces a restricted ability to form a complex view of other people. This is where identifying strongly with a particular Islamist group comes in, and why those group's ability to project a strong media image matters. Individuals who fill the other criteria are the primed but empty vessels they want their propaganda to reach.
Simplism - assigning single causes and remedies to complex situations that have complex causes and solutions, leading to ideas like killing everyone who isn't a Muslim will make the world a better place and is a good idea (or possibly that banning all Muslims from entering the US will make the world a better place and is a good idea)
This obviously doesn't describe every Muslim, and everyone described by this doesn't become an ideologically motivated mass murderer, but the links between these personality traits and extremism are not trivial, they're very strong. How this could feed into a pre-emptive solution without entering a very strange and oppressive world I don't know.