Doesn't Afghanistan want a part of Pakistan. Isn't the main reason they fund the Taliban was because they don't want them to attempt to reclaim the land so to keep Afghanistan fucked up and unstabilized. The same reason that a sub group of Taliban has premise in Pakistan is being the group that wants to be part of Afghanistan. If by some miracle that country becomes connected and stabilized that would be a huge problem for Pakistan.
This is much more just succeeding too hard you fuck up.
Pakistan's very powerful but also very short sighted secret service the ISI has one trick, which is supporting terrorist organisations. This has repeatedly backfired on them directly and also made them pariahs throughout their sphere of influence, except to China who want to use them to annoy India. However because supporting terrorist organisations is all the ISI knows how to do they will keep doing it.
I am about 99% sure Trump's decision to leave was a cynical, political, dick move.
My suspicion is that everyone knew leaving Afghanistan would lead to the collapse of the Afghan regime - the shock is just that it occurred much faster than expected. That's part of why Trump didn't leave despite all his rhetoric, because it would viewed as a defeat (Vietnam-like as you note) and he would not take that responsibility. Note how Trump instantly mocked Biden for suffering a defeat: that would be the same defeat Trump himself would have suffered had he gone through with his own plan.
The options on the table for Trump were essentially "Tell the American people that the US has actually been screwing the pooch extremely hard in Afghanistan for the last twenty-ish years and there's been a fundamental failure to create a stable, self reliant Afghanistan and there's going to need to have a huge rethink of the entire strategy which will necessarily include an indefinite extension to the entire project" or "Pretend the mission is accomplished, run away as fast as possible, and hope for the best", neither of which were very good choices. Biden had the same choices except the first choice would also involve U-turning on the withdrawal already in progress, which would have looked even more bad. There are a lot of people to blame for this mess, depending at what point you think things went badly wrong. In the context of US intervention it's definitely the fault of all the people in 2001 who thought they could have a nice quick war in Afghanistan and knock up a stable, friendly government and be home in time for tea, despite all geopolitical and historical evidence to the contrary, and also all the people in the succeeding years who knew it wasn't working out and didn't try to change tactics or blow the whistle.