But are they at war with another main faction when it happends?
I've noticed that as soon as peace happends - armies disband, and rebelclans dont count as kingdome, and thus they cant form armies to siege.
Bit of an oversight with the designdecision imo.
But overall the reason why they raid is to make it easier as the loyalty will plummet due to low security.
Thus only the garrison will be resisting the siege and not the milita.
Overall the ai tend to "raid too much" for my taste, specially when its counterproductive afterwards in maintaining control of the city aka prevent it from revolting.