I've forgotten where I read it, but Von Moltke (senior), after winning the Franco-Prussian War, had a flatterer compare him to Napoleon (the original Napoleon, of course, not his nephew Napoleon III whom they'd just defeated). Von Moltke demurred, saying that he had only proven his skills in advances, while Napoleon had been good at retreats, and that retreats are much harder.
It's an unusual statement; on first reading, I wondered whether it was entirely sincere or just a sly way to brag that he had won whereas in the end Napoleon had lost. But it did seem sincere, and bragging wouldn't have made sense. He hadn't conquered nearly as much as Napoleon had. Napoleon's ultimate loss was a matter of overambition and overextension, not of lack of skill on the battlefield. Von Moltke couldn't pat himself on the back for not going up against the Russian winter and the British navy, since the political aspects of the war hadn't been his job; they'd primarily been Bismarck's.
At first glance, retreating seems easy: on an individual level (as in self-defense), just run away. But you can't just run at the first sign of trouble; you'd be running from too many things; life would be impossible. Worse, predators (both two-legged and four-legged) know that being quick to run is a sign of weakness. Nor can you run forever; when to stop? When you don't see anyone chasing you any more? They might be just out of eyesight. The Bible says "the wicked flee when none pursueth"; but anyone who's scared might do that, and it might even be his/her best bet. Even having decided to run, in which direction do you run? There isn't always an easy escape route.
Now, when people who look like trouble start moving to close off your escape routes, that is a good sign it's time to run. But that level of tactical consciousness is a long way from the simplicity of "just run". One has to think about what trouble looks like, what makes it look bad enough to run away from, and what the escape routes are.
As the number of people involved increases, so does the complexity. Even at a family level, you have to decide to all run together; it wouldn't do to leave someone behind. Said decision might still be made in a split second by a family whose members were really in tune with each other, but it could easily take longer. Worse, in extreme situations you might actually have to leave someone behind.
In higher command, leaving people behind can become almost imperative. After losing a battle armies are disorganized; to buy space and time to recover, a common and effective tactic has been to leave men behind in blocking positions to slow down the enemy's advance. Those men are quite likely to die, with survivors being captured. Thermopylae was an extreme of this, but not an anomaly. People sometimes glory in such sacrifices, but actually having to make them oneself is just dismal.
The US military, in recent years, has had the opposite attitude: an extreme insistence on never leaving soldiers behind. The prime example is perhaps that of Bowe Bergdahl: after he had deserted, a huge manhunt was conducted resulting in the losses of several American soldiers' lives; eventually Bergdahl was traded for five senior Taliban commanders. Obama is commonly blamed for that trade, but he would probably have not even ventured to suggest it were it not for the military's pre-existing attitude of prioritizing retrieval of American troops above all else; and the initial manhunt was entirely the military's doing. That attitude extends down even to the lowest levels; it was also on display in the Blackhawk Down incident where Randy Shughart and Gary Gordon descended into the chaos of Mogadishu to aid a wounded pilot, on their own initiative and in full knowledge that there was little hope of them surviving. It was an extremely honorable thing to do, and they fully deserve the Medals of Honor they were posthumously awarded, but it didn't achieve anything worth the cost, nor was there much chance of it doing so.
Even civilians have picked up on this attitude, with the hit movie "Saving Private Ryan" being based on the idea that World War II generals would have sent out an infantry expedition to save the life of an individual private soldier. Really that's projecting the attitudes of the present onto the past: today's generals do such things, but in WW2 they would have rejected it as absurd. They'd have been willing to issue orders, to be passed down the chain of command, for some particularly deserving private to be released from duty; but to get several of their men killed to save one (as happened in the movie, and as was bound to happen one way or another) wouldn't have made any sense to them.
Indeed, the attitude of prioritizing soldier retrieval above all else amounts to a jettisoning of professional responsibility: pretending that hard decisions don't have to be made rather than realistically thinking about how to make them. On a political level it's a sop given to soldiers in exchange for not giving them a war that's worth fighting. But both the politicians and the soldiers can be sympathized with: the tasks they're dodging are some of the hardest tasks out there.
In the withdrawal from Afghanistan, it was already settled who would be left behind: the bulk of the Afghan National Army. It was the abandonment of a puppet state rather than an ordinary retreat, but that perhaps only made it harder. Dealing with people whose loyalties will soon have to change from "ally" to "enemy" is not easy. As Mers-el-Kébir showed, even Churchill couldn't always pull it off gracefully.
Of course that was a case of a peer-level ally, whereas the Afghans are technological inferiors. Once our aircraft are several thousand feet up in the air, the Taliban can't do a thing to them. But airfields need to be guarded, and not just in a small way. Rocket fire from 10km away (using simple, cheap unguided rockets) can make takeoffs from airfields quite dangerous; to make them safe, the perimeter has to be wide. Helicopters can take off from almost anywhere, but helicopters are short-range.
Suddenly withdrawing from Bagram Air Force Base has been widely panned as one of the main mistakes, and indeed it seems hard to disagree. For all the Americans to vanish in a night without telling their Afghan associates must have been a very demoralizing move for every government soldier in the country. One can see why we did it that way: telling any Afghans would most probably have resulted in the news leaking and perhaps a surprise going-away party of the very loud sort. Still, it's the sort of move that needs to get saved for the very end.
Rommel, in his World War 1 memoirs, relates an occasion when he broke into French trench lines, requested more troops from the rear to expand the breakthrough, and was told to return to his own lines instead. By the time that message got back to him (by messenger; they didn't have radios), the French were pressing him. He recalled a passage in the German army manual, "retreat is most easily accomplished after a successful attack"; he ordered his men into a quick attack which pushed the French back a bit, then immediately ordered a fast retreat, and they made it back to their own trenches.
That such things work is more a matter of psychology than of physics: someone who has just been pushed back will be thinking "what will he do to me next", not "what should I do to him next?" A really good enemy may see through such ruses, but few are that good. As regards Afghanistan, I'd wondered for a bit whether the reported rout was perhaps a ruse to draw out Taliban into an over-hasty pursuit and slaughter them, to buy a bit of breathing space -- but no, we weren't that good.
Something like that, though, was the real story behind the 1968 Tet offensive in Vietnam: often portrayed as a victory for the insurgents, to the extent that it really was a propaganda victory, but on the ground they got massacred, devastating the insurgency. It was more their screwup than our brilliance, but it enabled the "decent interval" between the US withdrawal and the fall of Saigon. When in 1975 that fall did occur, it was not to insurgents but to regulars of the North Vietnamese Army mounting a conventional invasion with tanks and artillery. The Ho Chi Minh Trail, which during the US phase of the war had been a mesh of winding footpaths through the jungle, had been paved over so that trucks could be driven down it all the way to the North Vietnamese Army's forward position in Lộc Ninh, a mere 75 miles from Saigon. Tanks, artillery, fuel, and ammunition had been staged there, with surface-to-air missiles protecting them from air attack. This was of course not well publicized at the time; even to this day most accounts focus on the way the South Vietnamese forces shattered in confusion. But although they did indeed shatter, it was in response to a very heavy blow. Propaganda had termed South Vietnam a corrupt "puppet government", but it was left to Afghanistan to show us what a real corrupt puppet government is and how little it takes to overthrow one.
In both cases, though, we see the problem of retreat just plain being hard. What pundits have quickly labeled complete incompetence is more a matter of everyday mediocrity faced with a very hard problem.