PolitiFact - Mitt Romney accurately says Trump administration worked to free 5,000 Taliban prisoners
There are many articles on the subject. It was done wrong to begin with. First of all, it was a "peace deal" between the US and the Taliban, the Afghan government was not taking part in the negotiations. 5000 Taliban were freed from prison, including leaders. That is enough to take over pretty much any city in Afghanistan.
It is postulated that there may have been some IS members in there as well, since there is some mobility between these groups. This isn't a major point though.
In my opinion, it was not a necessary step for a US withdrawal. They could have simply left the Afghan government in power.
Yes, I do agree Biden handled it poorly and should have pulled the troops out earlier. Likely Trump would have proceeded the same way, but there is a small chance he might have pulled the troops out earlier.
In any case, I consider it a major mistake to hand the country over to the Taliban, which is basically what Trump did.
I'm not even going to speculate on why he did that.