Someone mentioned Iraq. Iraq was stable country before the invasion - brutal, but stable.
Iraq's ISIS inflitration was just tribalism; they'd have ground to a halt as soon as they left the Sunni areas. Not quite as hilariously as when they fucked around with the Kurds and found out.
to tl;dr Sunni/Kurds in the north, Shiite majority in the south. The Sunnis (Saddam's people) fought like hell because they were afraid the Shiites doing to them what they'd been doing the Shiites. The US worked with the existing power structure assure them that wasn't going to happen, and the Sunni's put their lot in with the US & the government. The minute the US truly handed over the keys, the Shiites proceed to go full tribalism and fuck over the north. They put the northern Sunni army under incompetent Shiite commanders who only had being related to someone in power as a job qualification.
ISIS was largely Sunni, so the local population saw no reason to fight against people they had a lot in common with. The soldiers didn't feel a need to fight when their officers panicked and ran.
But ISIS didn't have a plan - they were even worse than getting shit on by the Shiites, and ISIS then proceeded to try to piss off everyone, and that's why they collapsed in about two years (that and a booster shot from US special forces).
There is a reason most Iraqi's when asked who the best modern Iraqi leader was will answer "Paul Bremer" with Saddam as 2nd place.
Anyway, Afghanistan is completely different. The Taliban were already 'in charge' - as much as anyone can be in Afghanistan - so they do have place. They are also running wild on areas that are ethnically aligned with them, and will stall out as they hit areas that aren't. That won't save Kabul.
And thanks to sleepy Joe not holding to the ceasefire time table, the Taliban also have a legitimate case now when they try to gather international support.
Honestly not that shocking. The one thing the American military is good at is fighting organized military resistance; put an enemy army in front of it and it will (more often than not) beat the crap out of it, especially when that army happens to be Soviet equipped Iraqi amateur hour.
The problem is such a force isn't designed for postwar occupation. The US military was honed by WW2 and the Korean War to fight legitimate state actors, not asymmetric insurgent groups. Vietnam should've been the wake up call, but Cold War fears interfered with that lesson and then Kissinger-influenced neocons decided that Fukuyama's "end of history" argument was perfect and the right way to make a fortune enlighten the filthy desert savages. Globalist ideals are entirely to blame for the resulting quagmire.
Its because the decisions are made by those who don't have to live with the consequences. And have family, friends, and patrons who profit from an ongoing quagmire. So they implement ROE that keeps you from shooting back or stopping them from fucking 8 year old boys. Can't actually shoot the guys laying IEDs because that's the Elder's grandson. Can't actually shoot the Taliban because they are not currently holding an AK, as they've learned you just dump your clip at the nearest NATO forces, drop your weapon, and can't be shot. And can't kill them, no sir, need to question them and then put them into prisons run by the same guys playing both sides.
And lets not get into what the cousinfucking has done to the genepool.
They should have dug up Blackjack Pershing and let him pass out the pork bullets and military govern the place.