This is a bug.
I have an army in a town.
Opposing armies are arriving.
I attack one of their armies, adjacent to the city. This makes my units 'go out' of town. The other opponent army which I did not destroy captures the city even though my army technically stands on top.
Yves