Hello.
It's because "divertirsi" is a reflexive verb and it is different from "divertire", that is non - reflexive.
Dirvertirsi = the action has effect on the person that is speaking (es: NOI ci divertiamo)
Divertire = the action expressed by the verb has effects on a third person (il clown divertiva il pubblico)
Reflexive verbs use "essere" as auxiliar, non reflexive "avere"
So:
"Noi ci siamo divertiti"
"Il clown aveva divertito il pubblico".
I hope I solved your doubt.