I wondered the same thing when I studied French years ago, but there is no rhyme or reason for ascribing gender to nouns/inanimate objects. It just
is. Like Nev says, you just have to learn 'em.
There's a book called
The Power of Babel: A Natural History of Language by John McWorter, which is a comprehensive history of linguistics. The concept of gender, of course, is discussed, but still no real answers as to
WHY.
At least in French it's only le and la. In German, you have der, die and das, and in some languages there are as many as 15 genders

I'm not in a position to explain or elaborate as I'm still trying to figure that one out myself