A hint could be found on page 32. Here it reads: “A submarine may submerge in combat after the attacker and defender have fired, regardless of what other units do.”
Now the words “may submerge in combat” could give a hint on how to deal with a defending sub when the attacker has retreated/submerged all of his units, as we could consider combat being over then: no more combat -> no more submerging.
This is correct. If the attacker retreats/submerges all units, combat is over, and the defender may not submerge.