I thought maybe, maybe this was mentioned in the great Peter Goudswaard’s Axis and Allies FAQ but unfortunately it was not.
Version 1.4 (the last one released): https://groups.google.com/g/rec.answers/c/dALhmZ-8gec
Section 2: Situations not covered clearly in the rules.
What defines a legal sea zone for withdrawing subs?
For attacking subs, this is more clear. Attacking subs must
withdraw to an adjacent sea zone from which any attacking
naval vessels came (Source: Manual, page 17, under “Where:”).
For defending subs, this is more complex. Defending subs must
withdraw to any friendly or unoccupied adjacent sea zone (Source: Manual, page 17, under “Where:”. But, what is unoccupied?
A sea zone becomes unoccupied when the attacker vacates it.
Source: Communication with Milton Bradley (dated July 27, 1995).
So, during the combat phase of a turn, a defending sub can withdraw into a sea zone that the enemy had left during that same turn’s combat movement phase. Thus, it does not matter if the attacking units that left the zone might or might not retreat.
Note: I personally disagree with this statement from MB, as it violates a principal that I have noted the spirit of throughout the rules. The principal is that “the state of the board at the beginning of the present turn defines what is legal.” This idea applies to legal landing spaces and use of canals, even to the point that, for example, if during the first turn Egypt falls to Germany and then the UK sub south of Turkey is attacked and missed, it can go through the canal even though Germany has already captured Egypt. However, I recognize MB as the experts and thus will accept it, pending further questions – Dewey Barich.
EDIT: Tried to clean up the text formatting a bit…