I feel someone who knows a gender language (French ect.) that genders words would be able to chip in.
Not exactly my DIR, but since this is a more general question and I see no point in opening a new thread on it:
The history of grammatical gender is a very complicated issue.
In the original Indo-European language, there was no grammatical gender at first, just different suffixes for making new words. However, those suffixes then started to influence the inflections, differentiating first the feminine and later the neuter nouns from the other nouns. But the words in question didn't have any semantic differences at that time that would be associated with gender. It was rather the case that the "feminine" suffixes were most often used to make abstract nouns, and the "neuter" ones to make plural-less nouns (like flour). Only due to the fact that some of the abstract suffixes were also used to make nouns referring explicitely to females, this inflection system became related to actual gender. But most words in these languages have their current gender either due to the suffix by which they were created, or due to later changes of morphological nature and similar (e.g. in German many nouns ending with -e are feminine, and so most of the remaining nouns in -e also changed to feminine in the last couple centuries).
Since there came to be more than one word for sun and moon and different words were retained by different languages we currently have e.g. "le soleil" (mask.) and "la lune" (fem.), but "die Sonne" (fem.) and "der Mond" (mask.).
But it is generally the case that words for sun tend to be masculine and words for moon feminine, i.e. while several words were available, those were chosen more often.
Maybe it's because of the same reasons that also in myths the moon often is associated with women?
For example, due to the menstrual cycle taking about the same amount of time for one lunar month? Or because when men created myths they associated females more with the night because that's when they were at home with them most often?
Also, independent of whether that's actually true, females tend to get associated with being more soft, changing and emotional, whether males get associated with being hard, individualistic and, if emotional then rather like fire. I guess you can see how that then relates to moon and sun.