The City Militia (the ones that automatically defend a city) can leave the city under the following circumstances:
- You have a unit that will be built in 1 turn
- The city is attacked on the turn that unit will be built
Both the new unit and the city militia will fight against the threat and if the city militia survives, they will be in an army with the newly built unit.
Note: the city militia does disappear if it is sent back into the city.
In this image, the militia unit shown is the one that had been summoned for city defense. It is not a built unit, it does not show up on my ledger nor does it have any cost/upkeep.