Very interesting question.
The fact is that we don’t really know why languages have things like gender, but many of them do. Gender is a form of sorting nouns into classes. Originally, of course, gender did start out by grouping things with natural gender. Words for women, girls, things associated with femininity were “feminine” and things for men, boys, and masculinity were “masculine” and this remains the case in most languages with genders. However, gender became a class larger than simply corresponding with natural gender as it came to be a way to classify any noun, including inanimate nouns.
I always saw it as a way of creating new nouns on different patterns. If Latin had no gender, then would all nouns end in ”-us”? That would fairly…bland. Having the gender allows for more variety of noun forms. But the fact is that other languages have different means of sorting and classifying nouns without “gender”; it seems to me that classifying nouns and having schemes for creating new words is a natural function and property of language. Gender arises as the means of this classification because natural gender is easy to observe and corresponds well with many words. Other words that had no natural gender were just sorted into this system arbitrarily.
But I’m just theorizing…I don’t really know for sure :)