If we do a surface-level examination we see that it made sense to go into Afghanistan like we did. If the goals were, as several people have mentioned in this thread, to 1) defeat AQ and 2) make sure AFG couldn't be used as a base to attack us again... well, to quote T.R. Fehrenbach,
you're going to have to put your young men in the mud.
Going heavy into Afghanistan made sense strategically. The Taliban were bad people and were helping facilitate disruption around the world by allowing various terrorist organizations free reign inside their territory. And if there's one thing that a global hegemon dislikes more than anything else, it's disruption. We were never going to fully defeat AQ unless we went in on the ground. We could shoot all the missiles we want, we can drop bombs to our heart's content, but we all know that in the way we fight today, decisive ops happen on the ground. And if we were going to make sure the Taliban weren't going to allow AQ to reconstitute, or other terrorist groups use their territory to attack us, then we had to invade.
Moreover, Afghanistan is super-strategically positioned. Landlocked and with bad neighbors, Afghanistan borders Iran (whom we don't like), three of the former parts of the Soviet Union (Turkmenistan, Uzbekistan, and Tajikistan), China (whom we don't like) and Pakistan (whom we... well, it's complicated). So having a US presence there, at say, Bagram airbase, would be great strategic positioning for us. If nuclear-armed Pakistan falls apart... we're right there. If Iran wants to get froggy... we now can threaten their east flank. If Russia starts breaking bad... we have a major air base super-close to their soft underbelly. Plus, yeah-yeah Al Qaeda blahblahblah.
So it makes sense... unless you start thinking it through. Afghans have a culture built around austerity and warfare. People like to say Afghanistan has never been conquered, but that's bullshit. Just about anyone who wanted to rolled over the country, from Alexander the Great onward. But no one wanted to keep it, because the Afghans are ungovernable. They can't even govern themselves. There was no way that we were going to make the generations-long commitment to doing what it took to make Afghanistan functional. Plus, the Taliban never saw themselves as defeated, and Afghanistan as only temporarily occupied. "The Americans have the watches, but we have the time." Plus, with our erstwhile "allies," Pakistan, not only allowing the insurgency to rest, train, and grow inside their FATA, but also directing Taliban proxies against us (looking at you, ISI and HQN), we never had a chance of being successful.
We also tried to foist a whole bunch of other people's pet projects onto to an Afghanistan that was not ready for it. We were trying to give "democracy" and centralized government to people who don't even listen to their local tribal chiefs. We did infrastructure improvement projects that the locals didn't want, and weren't willing to maintain. We gave the Afghans equipment like Blackhawk helicopters that were super expensive and costly & complicated to maintain. We were trying to build girls' schools in a country where women were cloistered and pederasty was not only accepted, but encouraged.
Going in on the ground made sense, but what also made sense was to go all Gulf War 1 on them and then go home. Maybe fund a little Northern Alliance for a while. Something. Anything other than this.