A lot of "nerds" have personal insecurities and downtime. The potent mix of the two leads to more gatekeeping behavior than is necessary.
It's for this reason that many people (especially women, PoC, etc.) will be hostilely quizzed when they express an interest in something nerdy. It's not overt racism/sexism, so much as a "oh no, if they share my interests, I'm less special" sort of reaction.
Unfortunately, nerdiness doesn't strongly correlate with emotional maturity.
But things don't have to be this way. We all have the choice of what kind of person we want to be. Some people just choose very poorly-- short-sighted selfishness that hurts them long-term and everyone else at all times.
There are a lot of "nerdy" individuals who choose better. I'm happy to know of at least 100 in my industry.
I’m skeptical that these are uniquely tech problems; I suspect they occur in relatively even proportion in other industries, but other industries have bigger problems that tech largely doesn’t have, and so they aren’t preoccupied with “toxic personalities”. In particular, the “tech is terrible” proponents need to explain why tech selects for toxic people more than other industries, and so far all such explanations depend on (toxic) stereotypes of whites, Asians, men, and people interested in technology (“nerds”).