I seem to remember that the troops did get kicked out before the AI declared war (I had total espionage superiority BTW). However, I was not at war when I tried to annex the city so maybe being at war prior to annexation allows the AI to stay in the city (which would be a bug IMO). Seems like some playtesting is in order.
"Annex city" seems to work the way I designed it. I did the following using a fresh install of 1.8 with no patches. Start any game as BG and autoplay 200 turns so that some other target AI player has > 5 cities. Using WB, for each city of the target player except the capitol, put 2 RM's. Put 10 spymasters into one of that player's cities. Put a heavy carryall somewhere on land, outside the target player's borders but within one move of a target city and put 6 kindjal soldiers in the same plot. Exit WB, pop all 10 spymasters so you have a huge number of espionage points, load the kindjal soldiers onto the carryall and save the game. Now do five experiments.
1. While at peace with the target, and with open borders, annex a city. Unless you are unlucky, the target will not declare war. You can see that you get control of the city; it is in revolt; and the target player's units stay put. This seems fine.
2. Reload the game and drop open borders. Then annex a city. You can see that the target player's units "bounce" to the nearest plot owned by the target player, just as other situations in which it is suddenly no longer legal for their units to be in your territory. This "bouncing" can be unexpected but this seems fine also.
3. Reload the game, declare war on the target, and then annex the city near where you have your heavy carryall. You get control of the city and the enemy units are moved into the next plot. Although you have your carryall nearby, do not move it. Hit next turn. The enemy units will take back the city. This also seems fine to me. If you are at war, and you take a city but cannot defend it, the enemy should take it back.
4. Reload, declare war, annex the city, and move in your troops. This is the recommended approach when you are at war. This probably guarantees you will keep the city.
5. Reload, and annex each of the cities one by one. Look into the diplomacy screen and you will see the "You manipulated us" penalty grow 1 point per annex. As in #1 or #2, the enemy troops will stay put or "bounce". At some point, randomly but probably after 3-4 annexations, the target will declare war. When this happens, look back at the cities you already annexed, and you will see that all of the defending troops have been moved out of the cities.
As you see, there is no case where the target automatically takes back the city. If you don't have units to defend your new city against an angry enemy, you should lose it.
Are there any suggestions for something to change, or disagreement about any of the cases?