I've run into this bug as well its pain to organize troop when defending castles and settlements because I am literally having to climb the walls in order to get ready. Btw I am the king/emperor and on xbox series x. Even if I get to the settlement/castle first it still happens. The only work around I've been able to find for it was to ambush them during the siege forcing the AI the reconize me as the commander, but only works for the one engagment and I have to repeat the process if they retreat.