"lui" doesn't match the gender of the owned object, but that of the owner, indicating that the owner is masculine, so "his". This would be the same with a feminine noun:
Femeia are cartea lui. - The woman has his book.
Similarly, "ei" reveals a feminine owner:
Femeia are paltonul ei. - The woman has her coat.
Femeia are cartea ei. - The woman has her book.
I'm not sure if these are the grammatical terms, but I think "lui", "ei" and "lor" (plural) are genitive pronouns and they show the gender of the owner, whille "său", "sa", "săi", "sale" are possessive adjectives and they mark the gender of the owned object:
porcul său - his/her pig
vaca sa - his/her cow
porcii săi - his/her pigs
vacile sale - his/her cows
(note that there isn't anything similar for "their", so you have to use "lor" which doesn't vary by gender)
People coming from a language with reflexive possessive pronouns
You might be tempted to believe that this is how the "s-" forms behave, but you can actually use them without a callback to the subject:
Mie îmi place paltonul său. - I like his/her coat.
And you can use the genitive pronouns to refer to the subject:
Femeia are paltonul ei. - The woman has her coat. (as ambiguous as in English, it could be her own coat or someone else's).