I think this is a bit tricky and hard to get without explanation. As stated above, usually the participle is only changed in gender and number if the auxiliary is essere, not avere. However, there seems to be an exception, namely when there is a direct obect pronoun. Then the participle has to agree with the direct object pronoun. This was also stated above: "Lei ha fatto la torta" but "Lei l'ha fatto". There was another expample: "Noi ce l'abbiamo fatta". Here, it is fatta (not fatto and not fatti) because the "l'" is a feminine object pronoun. Another example: "Ho ascoltato voi" but "Vi ho ascoltati" where the participle has to agree with the pronoun "vi".