If you defeat a faction by killing all family members, their towns revert to rebel even if they should have nothing left in them.

If the battle had happened in the city, the city would be yours. But since the battle occured just outside the city (even though it contained the city forces) the game calculated that the faction was destroyed, setting the city to rebel and giving it a new garrison, before it calculated that a seiged city had no garrison, forcing it to surrender.

I've had this happen many times.