Not everything has an evolutionary advantage. Nature isn't perfect. Androgenetic Alopecia isn't the result of a genetic mutation.
I agree. It's a mistake to assume that the existence of baldness means it must have/had a purpose.
But consider the sheer impact it can have on somebody's attractiveness. I think that is at least a strike against that idea that it never had a purpose. We're not talking about a few extra skin moles or a slight height difference that shows up in 6% of the population. We're talking about something very widespread with a big negative impact. Nature does not take that kind of thing lightly.
There is the matter of age. Baldness usually doesn't show very much until past the peak ages for fathering children (in pre-industrial times). But on the other hand men never entirely lose that ability and women are still attracted to middle-aged men in general.
When would a man need more sun exposure? Maybe as he got older, and more of his face was covered with a thicker beard, and he became more averse to cold so he was dressed more heavily on average? That would line up with the progression of baldness over the lifespan.
The vitamin D explanation checks off more boxes than any other suggestion I know of. I doubt the condition purely evolved because of a major selection pressure for it. But IMO it may have been a combination of chance + mild/moderate selection pressure to keep it.