This question is a little bit about history and culture, but it has been a question since I've watched a live show. Well, I've "Googled it" before, and I've got some answers but none of them were really right. Some believe it's because some musicians(especially rock musicians) are against the [usual] social norms so... but some others believe that's because they sometimes wanna headband so it gives them a good feeling.(!)
I think it all started with bands like the beatles that, as you said were against the social norms (at least in terms of appearance). Generally rock music scene always wanted to be against the norms and to shock, with it's lyrics, with it's loudness and with the band's appearance. Headbanging was not that popular until the late 70ies/early 80ies so I think that it was a sub-product of trying to go against the norms.
Hair length on men is generational and cyclical. In 40's and 50's America, short hair was culturally enforced. Hair length increased to a peak in the 70's, then reduced in the 80's, 90's and 2000's.
Musicians tend to be ahead of the cultural curve and to shape it. Because it came of age in the 60's, rock music became strongly associated with long hair. Even newer rock musicians in the older sub-genres (classic rock, heavy metal) tend to keep to this convention. Conversely, punk rockers tend to have short haircuts.
It's worth noting that this really only covers white male rock musicians. It's not necessarily generalizable to anyone else (although similar processes are at work elsewhere in the world of music).
As both answers have noted, the long hair tends to go against social norms. Musicians have something to say, and one way to get noticed is to keep your hair long. Also, let's face it; chicks dig it. A lot of it has roots in the 60's, when men began to grow their hair long as a protest to "The Establishment". However, once fame and fortune are found, you're married and you're no longer young and angry, the need or desire for the longer hair can wane. Both Lars and James from Metallica abandoned their long hair a while ago, and John Petrucci from Dream Theater did the same. James Taylor cut his hair in the 80's and has left it short. There are hundreds of other examples as well.
So, I'd say it's probably most related to the "buck the system" mentality of youthful musicians, coupled with an homage to the look of their idols/influences.
I think its a love thing.. watching exceptional stuff ,watching long hair musicians hero fav guitarist or drummer or any kind of wild musicians metal or rock stuff players they all have long hairs 90% at least once in their lifetime . when you grow ur hair long ..u cant cut it off. its like a child to me.dont care I am looking bad or smart but end of the day I did it. I grow my hair in this society.i have my dreams .just let it go with flow. long hair men are great . they know how to stay in the line of their dream track.