In addition to the article cited by Veredomon, I suggest watching the video by the same author (Belles Lettres).
Gist: Grammatical gender is less about actual, prescriptive 'rules' as such, but more about usage and slowly developing consensus.
(Note: The video is 84 minutes (!) long and includes pretty in-depth
background information on linguistics, language history etc. - a lot
of the things he says won't make sense if you haven't at least a
nodding acquaintance with this stuff. Also, his choice of examples is
sometimes a bit off, but he makes several excellent points.)
This guy does offer a (for me) somewhat surprising view on the topic:
He shows that the grammatical "genus" has only a more or less coincidental connection to "gender", because "Mann" and "Frau" were thought to be somehow "representative" of their grammatical category (genus). What had happened in early history was that people started to use additional endings to express certain aspects.
The first addition was a group of endings to say that "this is an inanimate object" - this became the "neuter" genus.
The second addition was a group of endings to say "this is a group of
things/people" - this became the "feminine" genus.
The nouns that didn't take a new ending stayed in the "old" default
form - later called the "masculine" genus.
So, no real gender, just grammatical categories that got rather muddled over time.
The bit of the video that was really stunning was how he showed the way this allows pretty accurate predictions of what genus new words will likely develop over time. (around the 00:34 mark). This will blow your mind. :)
PS: This is a slight modification of an earlier answer to a similar question.