Usually when I set up an encounter that is deliberately 'too tough', I will foreshadow the difficulty clearly, or set up the encounter in such a way that retreat is easy. I might have the opponent first kill off an npc, to foreshadow its attacks.
For example, I had a crocodile first eat an npc prisoner, before it turned on my level 1 players. This informed the players that the crocodile could reduce anyone to 0 hp in one attack, if they got too close.
Sometimes I will simply have an opponent do a ton of damage to the strongest player in the party, but facilitate an easy escape.
For example, I had my players run into a Chaukeedaar, a powerful animated statue that had six arms and does a ton of damage. During one round it easily knocked half of the hit points off of the main tank of the party, but I also described how it tried to stay away from sunlight. At first the players thought it couldn't stand sunlight, but then it became clear that the statues froze during the day, to hide themselves from the gaze of a vengeful god. The players blew the roof off the ruins, to expose the statue to the wrath of the angry god, thus destroying it. However, the rest of the island was still crawling with these statues, so they decided to return when they were stronger. During this fight they could also have simply left the ruins where they encountered it at any time. They were not obligated to fight it.
I think it is a mistake to design an encounter in such a way that fleeing is the only option. I don't think encounters should be scripted like that. If you set up an encounter where the players must flee the dragon, they WILL fight it. I guarantee it.