Was this in classes for English as a second language?
Because, as a native English speaker, this seems like misinformation to me, perhaps partly influenced by your teacher having a first language where nouns do still have gender.
This a weird memory to be honest. Yes,you are right, English is a second language and normally sun and moon would be 'it' and not 'she' or 'he'.The teacher was too good to get mixed up when it comes to genders but because it was more than 20 years ago,I've got a feeling that there was more into it.Maybe it is how it used to be in onld English or something.
As an native speaker I think things that are personified have an aura of gender. Impersonal objects do not. Ships are female for instance. And you use the proper pronoun. The earth is feminine but you don't.