>>The war was justified to begin with on the pretext that we had to find the terrorists responsible
Let's be clear here: we went in because of fear of another 9/11 attack. No pretext. Al Qaida was there - and their Taliban hosts, although uninvolved in the attack, refused to hand their guests over. Protection of guests is one of the tenets of Islam, and the Taliban were... fundamental on the issue. So no real choice if we wanted to degrade Al Qaida's ability to launch another attack.
This was complicated by the neo-cons' use of 9/11 as a pretext to also invade Iraq - at which point almost all attention was diverted from Afghanistan. We were approached by the Taliban in that first year to make a treaty, but instead we drifted into state-building, even though we had the Russian fiasco in recent memory - and were fighting the same mujahedeen that had prevailed.
By the end of Bush Jr's administration, we were in deep enough that any withdrawal was going to be a disaster - it was just a matter of who had enough political capital (and courage) to get us the hell out.