I suspect it is somewhat similar of women looking at each other and judging each other about "giving out free milk. Biggest slut shamers are women, tho men are right after them lol.
So from a purely guessing point of view:
Place in society, and perceived safety of norm enforcement and the fact, that historically being gay was (almost/mostly) a death sentence.
Raising yourself up by hating someone else "at least I am not XYZ" or "it would suck to be XYZ I'm so much better" is an easy copium.
And distraction also: if you hate someone else, you won't have time to hate yourself.