I could be way off, this comes soley from my experiences in the world and observations on here.
In school, those of us who got into metal were already seen as different beforehand, they maybe came from a shitty upbringing, or they looked different than what is expected, or they were interested in things which deviated from the mainstream.
That's all well and good when you're younger. When puberty hits on the other hand, and your emotions end up in turmoil, it became difficult to process why you were excluded from the group so to speak, which caused the resentment and anger to simmer. Then you discover several genres of music, the most mainstream examples of at least. The bands look different, their music hits home on the anger you feel against the world, you embrace it.
As time goes on you expand, you find different meanings in different sub genres and gravitate to the ones whos message means the most to you. Ontop of that you see the music itself can be beautiful, complex.
Of course, that was a generalisation, I understand not everyone gets into metal the same way, or the meanings are the same for everyone. Now look at nerds though, again in general. Look at the number of threads on here concerning how many of us are single, how many are useless in social situations, how many were bullied and ridiculed for not fitting in. The same feelings will be there for many, bubbling away under the surface and the result will be many will see metal as a release for the anger and frustration.
This is perhaps why the so called "true" metalheads despise more mainstream bands or that the genres as a whole are becomming more popular, because metal or their chosen sub-genre justified their being different. They found a way to embrace being the outcasts they found themselves, and dislike the encroachment of the mainstream. I see the same similarity with gamers/nerds. Look again at this website and you'll see how the casual gamer is dismissed.
So really, the two fit together quite nicely. It isn't true for 100% of people, but then nothing is.