Usually just insecure people who hang around with other insecure people who always need to prove their toxic masculinity to each other. Then others get roped in because you get excluded from the group if you don't get involved. It's very tribal and stupid and fortunately it's getting less and less common amongst younger men.
And obviously religion plays a big part because being gay is sinful in many religions.I suspect a lot of it got worse around the time Christian values became the "default" cultural representation for pop culture in the west.