I suddenly realized that I can't clearly articulate when the AI will leave its Castle, and when it won't, and consequently, when it will break through using a teleport/clone, and when it will only do so through a force field.
Typical situation: the AI has dragons/phoenixes, archers are without shots/blinded/have forgetfulness, the AI is out of mana, and it has no archers of its own. What will the enemy flying units do?
There are no clear rules. From my experience, the following factors influence this:
1) The composition of your army: if there are no flying units and archers, the AI will definitely not leave.
If there are very strong and dangerous stacks, for example, gray bears, the AI will delay leaving.
2) The composition of the AI's army: if there are archers, it will likely stay in the Castle, unless you have an advantage in archers.
If the AI has only flying units, it will definitely leave.
3) The ratio of your archers to its archers. The more the AI has, the more likely it is to stay in the Castle.
4) Whether the AI has a tactic. If so, and it is stronger, it will likely leave the Castle to attack.
5) The archers of the AI running out of shots, forgetfulness, or blindness affecting its archers. If you have an advantage in archers, the AI will leave.
6) What spells you and the AI have. You can see in YouTube tests that even with equal strength, the AI may leave or not leave. It all depends on whether the AI has, for example, an "Explosion" spell, or you do.
7) Traditional Chinese strategy: if you only have summoned elementals left, the AI will not leave. You can do whatever you want with magic.
8) If your flying unit enters the AI's Castle and is not killed, for example, it gets stuck in a corner near the archers, the AI will definitely leave.
9) And whether the wall in the Castle has been broken or not. If so, leaving/exiting is almost guaranteed.
That's all I can think of for now. Also, from personal observations: Inferno and Castle factions tend to stay in their Castles more often. Also, if your army consists of archdevils and/or vampires, you have no archers, and the AI has faster units, it will also not leave, even if you cast mass slow on them.