One of the most common Qs they ask is why there are masc / fem nouns for inanimate objects
There are two separate questions:
1. How did the modern Romance 2 gender system evolve out of the Indo-European 3 gender system, which Latin still had and
2. How did the Indo-European 3 gender system develop in the first place.
Ad 1.: By and large, the Romance masculine developed out of a merger of the Latin masculine and neuter (there are a few gender changes, like Latin mare yielding, as expected,
il mare in Italian but
la mer in French). The reason for this merger is simply morphological: With the loss of the case system in Proto-Romance, only one form survived and this was mainly the accusative form. For the most typical declension paradigm of masculine and neuter nouns, the 2nd declension, the accusative singular ending was
-um, which developed into the predominant
-o ending for masculine nouns in Proto-Romance.
Ad 2.: One theory is that the 3 gender system developed out of an earlier 2 gender system based on an
animate-inanimate distinction rather than out of a masculine-feminine distinction. There is no general consensus on this theory and it has fierce critics but by and large, it is the most popular one.
In this theory, the
animate-inanimate distinction worked a bit differently than we naively understand it today: It had more to do with semantic roles in a sentence. An animate noun would be one, which could be used in an agent role in a sentences while inanimate nouns were (mainly or exclusively?) used in a patient role. The early case system was very simple and essentially consisted only of a subject/agent marker, the
-s ending, which later became the masculine nominative ending (in Latin
-us in the second and
-s in the third declension). In this theory, the inanimate gender had two separate plural forms, an individual and a collective one. The latter was later re-interpreted as a singular and developed into the third gender, the feminine. The morphological similarity of the 2nd declension plural neuter and the 1st declension feminine singular would then be a reflex of this development.
See also this early discussion:
Evolution of word gender in languages.
and why adjectives have to agree
I am not aware of any elaborate theory how agreement evolved, so I can only present my own theory/understanding. Case agreement was probably originally the more important one and gender and number agreement was more of a by product but in modern Romance, only those survived. Early languages probably did not systematically distinguish between nouns and adjectives. In fact, even older English grammar terminology, influenced by Geek and Latin grammar systems, spoke of
substantive nouns and
adjective nouns. My theory is that attributes originated as a kind of apposition:
the red ball < the ball, the red [one], where the apposition repeats the first noun with a different aspect and where one would naturally assume the apposition to agree with the original noun in declension. But this just my idea. As I said, I am not aware of any learned theory of how agreement evolved.