I haven't heard this put like this yet, so i'll spell it out here:
There was a second generation Muslim brought up in the mosque, who took his religion pretty seriously, seriously enough to pull out a knife when gay compatriots made fun of religion in conversation. What's wrong with this picture? Technically there should be no gay Muslims, but in Mateen, we had this paradox. Seriously gay, seriously Muslim...and it became apparent to his sense of awareness, that his salvation was seriously in jeopardy as a result. Probably he would have continued living a double life as a married (to a woman) Muslim man by day, and single gay man by night...except that it sounds like he had a bad experience among his gay relations, and suspected he might now have HIV. Now his day of death is that much closer, and he still hasn't got his salvation straightened out, according to Islamic indicators. So he's mad, and now he's also worried about his salvation. Everything that happens after this is all about securing his salvation, according to core Islamic guidelines. Offering allegiance to ISIS is about securing salvation...as much as yelling "Allah akbar" is about obtaining salvation (dying while yelling it assures salvation as a martyr). There is also an effort to deceive Allah into believing that the gay Muslim man is not really gay at all, or that he is sorry for being gay...by killing as many gay as he can before dying in allegiance with ISIS, the face of ORTHODOX ISLAM.
We likely would not have seen this if he was not brought up in a mosque and did not take ORTHODOX ISLAM so seriously.