Vitamin D may be more important that I imagine, and is worth considering, but don't people that absolutely never wear hats also get hair loss?
Funnily I remember this one study done on twins.
The contribution of endogenous and exogenous factors to male alopecia: a study of identical twins. - PubMed - NCBI
Daily hat use (p = 0.050), higher body mass index (p = 0.012), and higher testosterone levels (p = 0.040) were associated with decreased temporal hair loss.
Wearing a hat preserves blood circulation to the scalp.
Factors that were significantly associated with increased vertex hair loss included abstinence from alcohol consumption (p = 0.030), consumption of more than four alcoholic drinks per week (p = 0.004), increased smoking duration (p = 0.047), increased exercise duration (p = 0.050), and increased stress duration (p = 0.010). Lower body mass index, more children, increased caffeine consumption, history of skin disease, and abstinence from alcohol were significantly associated with increased hair thinning scores (p < 0.05).
The increased exercise duration reminds me of how bald people are often neurotics and try "too hard", including in exercising turning an healthy habit into an unhealthy one. The abstinence of alcohol probably points to a basal serotonin/stress level where one can't even support a bit of alcohol, but when it is done from conviction it should be beneficial (mormon men tend to age well).
Also one must not forget the effect of UV-B, not on the scalp but on the skin which will reduce systemic keratinocytes proliferation (which IGFBP3 reduces). An excess of keratinocytes between the scalp and hair follicles would decrease blood circulation and make it calcify. There is a bunch of links to be made between skin disorders and male hair loss, and a moderate dose of UVB helps many skin disorders. There is this one case-study of an old man taking a psoriasis medication (which reduces keratinocytes proliferation) and had hair regrowth after being bald for many years.