[This should be a comment, but I need room].
As remarked earlier, this feature is shared by French. I'll use French examples, because I'm sure to produce correct and idiomatic sentences in this language.
The rule we are talking about has two aspects:
When the compound tense is built with “to be“ [essere / être], there is agreement between the past participle and the subject. When the tense is built with “to have” [avere / avoir], the agreement, if any is between the direct object and the participle.
In the “have“-case, there is agreement if and only if the direct object precedes the verb.
Some examples :
Marie est venue. (Marie has come.)
J'ai mangé une pomme (I've eaten an apple.)
La pomme que j'ai mangée était verte. (The apple I've eaten was green.)
My point is that the first part of the rule is perfectly logical. The choice of the auxiliary verb (to be vs. to have) depends on the verb you're conjugating. (Very) roughly speaking, transitive verbs use “to have“ and intransitive verbs use “to be“. Let's also remember that, taken in isolation, the participles of transitive verbs are adjectives. When I eat an apple, what's eaten is the apple, not me, so the agreement with the subject would really be weird. In the other case, agreement with the subject makes sense (in some cases, it is even hard to tell if we're dealing with a verb at a compound tense or with “to be + adjective“; for example « Jean est mort » can mean both “Jean is dead” and “Jean has died.”)
The second part of the rule (and all the subtleties I've hidden [pronominal verbs, special constructions with « voir », « faire », « laisser »...], which are very complicated and largely ignored even by native speakers) is indeed much more artificial. It's also noteworthy that before grammar was taught in schools, there was a lot of variation concerning this part of the rule. Voltaire, for example, systematically left the past participle without agreement (he would have written “La pomme que j'ai mangé était verte.”) [Chervel's Et il fallut apprendre à écrire à tous les petits Français, a marvelous book about the history of school grammar, even makes the case that the development of school grammar was in no small part motivated by this question of the « accord avec l'auxilliaire avoir »]
There are other cases where French grammar asks for an agreement if and only if the part that triggers the agreement comes first, but they are mostly unimportant peculiarities. For example, “barefoot“ is « nu-pieds » or « pieds nus », you write « une heure et demie » (an hour and a half) but « une demi-heure » (a half-hour)... (To be perfectly honest, I wonder how many native francophones know about these rules...) So we could say that, while peculiar, even this artificial part of the rule belongs to some logical framework (but as the other examples are even weirder than the rule we're discussing, this argument doesn't sound very convincing).
A final comment: this rule is very often infringed in speech, even among educated speakers (with a very large tendency to left the participle uninflected). Interstingly, women (who have to apply it in sentences like « Il m'a remise à ma place » = “he put me in my place” ; a man would say « remis ») tend to respect the rule more carefully than men.