Because they fucked up. Beer is feminine, sugar is masculine?
Unless the nouns were named with regard to the stereotypical gender coveting a given object, ie. men want beer, so beer is feminine, and so on with sugar and, one would presume, the rest of the language (albiet with rampant exceptions).
In all probability, this will prove a daft notion. But, it will be researched further.