Whenever a carrier is attacked, its planes are assumed to be launched and defending in the air. This is not optional. If the carrier is hit, the planes can’t land on the carrier and must find another place to land within one space or be lost.
The only way that planes can be trapped on board a damaged carrier is if there are planes belonging to an ally on an attacking carrier. Since it’s not their turn, the planes remain on the carrier as cargo rather than participate in the battle. If the carrier is damaged during the attack, these “guest” planes will be trapped (unable to take off) until the carrier is repaired. If the carrier is attacked while still damaged, the planes will remain cargo. They will be unable to launch and defend, and will be lost if the carrier is sunk.