Consider the alternative - they couldn't leave their fragile client government that would likely lose to the Taliban. Which is exactly what happened when they left, although much quicker than anyone wished to believe.I simply have a hard time believing they spent 20 (not 5 or 10 - when they killed Osama and somehow met the primary goal but 20!) years in Afghanistan to end up like this without any measurable or even collateral profits.
Also consider how there were significant troop withdrawals in the last years, so there were less fighting and less soldiers already. If the conflict was ruled by shady weapon manufacturers, they would have wanted a full scale war where expensive munitions are expended freely by a great number of troops, not a seasonal low intensity conflict.
My thesis is that you would have done the same if you ruled the US, because it makes sense, sometimes strategically, but more often politically.