I think it's definitely related to masturbation, although probably not the sole cause. I think malnourishment and stress are other big factors as well.
There's too many people who've reported hair regrowth on NoFap for me to believe masturbation has nothing to do with it, plus enuchs/people who've been sterilized also report hair regrowth. DHT is the primary culprit of balding, because it blocks the pores from getting the necessary nutrients. When we orgasm, our testorone turns to DHT.
Also , I don't think genetics play the main role at all. Many of my family members including uncles and cousins started balding at different points in their life. One cousin of mine was already significantly bald by the time he graduated. Yet several of my uncles on same side of the family have full heads of hair in their 40s.