Let's try to break down the layers of the problem here, why fleeing isn't coming up as an option to be taken.
A key problem is the limitations of communication; they just aren't able to have a debate about how all their coordination in attack is a massive waste when really they should be doing the opposite and running away. No one wants to be "that idiot player" who refuses to attack but retreats instead. The result is everyone keeps attacking to keep with expectations and any left behind will naturally be focused for damage. They focused on attacks to dominate, there's likely been absolutely no discussion of how to make a fighting disengagement. This is actually something military personnel are drilled on a lot, how to maximise their threatening capability in a fighting retreat.
You have got to introduce the idea of retreat outside of initiative when they have time to talk with the idea. Even give them a specific quest mission where the objective is specifically spelled out "do not kill this creature, just lure them away".
PRIMER THAT PROMPTS A REAL DECISION
What will not work is to try to prompt them with a situation they can literally definitively do nothing about the situation except run. For example they cannot attack rising flood waters or lavaflow, their only possible option is to run away from the threat. Then of course everyone is thinking "sheesh, I don't want to be 'that idiot player' who doesn't escape". No one has actually learned to communicate on group decision making.
An example of this is you racing to get to a boat in time and you get a tip that a group of low-rent mercenaries has been sent to slow you down but are explicitly told that they aren't expected to beat the party of adventurers, only slow them down. This introduces the team coordinating on the group decision "lets disengage and move on instead of fighting" without the fear of leaving anyone behind as these ruffians are tough with their tower shields and heavy plate but have rather useless one-handed weapons.
ELIMINATE DISTRACTIONS FROM FLEEING
After that you have the idea of fleeing from the big fight be sure to account for how they might be distracted with the benefits of winning the fight where they can take their time exploring around the area. Have the "fight or flight" be in a room they've already searched for every possible item or clue then repeatedly go over the possible escape means. You can also subtly guide their intuition and lead to the situation getting worse and worse.
What I did was have them return yet again to a large domed room with an opening high above them, I don't actually tell them it is the same room but by describing it the same way they figure it out. There is no reason for them to stay, they have got the thing they are looking for and have searched the area totally. When the skeletons begin rising from the dead and with fast healing cannot be destroyed it seems they are doomed.
When a rope is dropped from the hole above them everyone in the group is clued in to the same thing: this is our way out. The group isn't divided about staying to keep trying to destroy the skeletons to search them for a third time.
GUIDING WHAT YOUR PLAYERS ARE THINKING
You can use a bit of reverse psychology. If you have the Big Bad taunt the heroes "Ha, there's no escape! Give up!" It just introduces the idea of escape, there's the tendency to prove the villain wrong. The big bad backing it up with "don't let them escape you fools!" further reinforces that their antagonism being faced is against them escaping.
To help them along, have an NPC appear to at great risk show them a novel and cool way of escaping. One thing I did was have a person they held prisoner suddenly run into a wall that turned out to be a fake plaster wall painted expertly to look like a rock dungeon wall. Plus, the prisoner is escaping you have to go after him.
MOST IMPORTANTLY IS THE RULE OF COOL
If the means of escape is simply running away then that isn't too exciting, but if it is to cut the ropes next to a pier and swing across onto a boat, that is fantastic. If it is a do or die leap over a chasm, that's also great, if it's running across a rickety bridge and luring most of the enemies onto the bridge before cutting it, rule of cool.
Have escape be something exciting, something adventurous, something that you'd have in an Indiana Jones movie or something. An underground water channel, hopping on a runaway minecart, cutting the line holding balloons and floating up and away, shoving a raft onto fast flowing river that leads to rapids.