I'm honestly not surprised.
As far back as 2016, about half of the districts of Afghanistan were under the de facto control of the Taliban when night fell. There was also a priority of overlooking the Taliban (to the point of practically supporting them) in order to contain ISIS in Afghanistan - who were and continue to be a very minor threat by comparison.
Beyond that, the Afghanistan Army only had one capable combat unit, it's counterterrorism forces that had been trained by the US - beyond that it was graft and corruption all the way down. Not to say these guys aren't fighting, because they are - Afghan forces have taken more casualties in some years than the US has had for the entire invasion - but when your commander is stealing the pay and will have you beaten to death for complaining, there's not going to be a whole lot of loyalty.
Of course the problem is more entrenched then that, in that the US never had a plan on how to integrate the Taliban back into power on any level. How best to put this...? In any kind of war, you have two options. Either you're going to kill absolutely everyone who belongs to the enemy team, precipitate a massacre. Or, at some point, you need to sit down and talk with them. Most historical war tends closer to the second, war is a continuation of politics by other means, military force is used to gain the most advantageous position in the negotiations to follow. We see this with regard to things like Nazi Germany - while the hardcore were (rightfully) hanged for their crimes, former Nazis with relatively minor blood on their hands were put in charge of Germany while the Occupation forces set about establishing ground rules. No-one liked it, but you needed these people to convince the ones behind them to lay down arms and agree to the new way of doing things.
And then you have the "no people, no problem" approach. However, and importantly, this does rely on you actually being able to kill all of them, which in Afghanistan was always going to be tricky.
Now the US had the chance to do the former. In 2001, the Taliban offered to put Mullah Omar under house arrest, enter negotiations to lay down arms and act as a political party in the new Afghan government system. Rumsfeld told them to piss up a rope, because the US policy at the time is "we do not negotiate with terrorists" and "we do not differentiate between terrorists and those who support them". That's the message they wanted to send, and as rhetoric goes it's not bad. But turning down the deal allowed the Taliban to disperse physically, build up support among the Pashto clans and tribes and put us in the situation that exists today. Between having no end-game for the conflict and not being willing to supply the forces necessary to achieve the outcome they had decided to pursue (again, logistical difficulties played a role here - supporting that many troops in Afghanistan would be hell on public finances) they always put themselves in a position where they'd be propping up a government with only partial legitimacy.
And this is without going into the very real clustefuck that is competing agencies in Afghanistan. The political types were cut out by the Pentagon. The Pentagon and the spies played at loggerheads. Different branches of the Pentagon pursued their own policies. There's whole books that focus just on that and that there wasn't a single person who ultimately controlled Afghanistan policy is part of the reason why it turned into a clusterfuck, other than the more theoretical problems of war termination presented above.
And so the moment they moved to leave, it was always going to come tumbling down. That it tumbled down this fast is mostly because the Taliban are very organised and already had an advantageous position due to previous decades of war minsmanagement.