It seems that sun was feminine and the moon was masculine in Old English up to about the 16th century:
"sun (n.) [...] Old English sunne was feminine (as generally in Germanic), and the fem. pronoun was used in English until 16c.; since then masc. has prevailed." [1]
"moon (n.) [...] A masculine noun in Old English." [2]
[1] https://www.etymonline.com/search?q=sun [2] https://www.etymonline.com/search?q=moon