To know the reason for why USA lost in Afghanistan, one must first ask why USA came to Afghanistan in the first place????
Invasion of Afghanistan had already been decided in the late 90s by the US establishment. Read about
"Project for the New American Century". Bush, Cheney and others signed on the principles of PNAC and then they all worked in Bush administration 5 years later. PNAC was meant to be blueprint for US foreign policy to fill the strategic locations which were lying vacant after USSR went down.
USA had many Geo-strategic objectives to be in Afghanistan. It had nothing to do with terrorist BS btw.
The strategic objectives for USA to be in Afghanistan were:
1) Encirclement of China
2) Encirclement of Russia
3) Close proximity to Pakistan
4) Close Proximity to Iran
5) Control and eyes on resource rich CARs
6) Trillion dollar worth of minerals/rare earth metals in Afghanistan
7) Billions of dollars worth of poppy cultivation/opium trade which CIA then uses to cover other covert/terrorist activities in other parts of the world.
8) Testing of Chemical/Biological Weapons and other weapons (Drone warfare which US military tested and mastered)
9) Protection of Israel and Pakistan being only Muslim nuclear state poses a threat. Hence to denuclearize Pakistan.
Their main objective was to destabilize and then eventually denuclearize Pakistan. But they failed miserably.
Now to your query about why USA lost.....
Here is what I think why USA lost in Afghanistan.
1) Relying on warlords. After the Taliban were removed from power, CIA brought former Norther Alliance warlords back to power. They were all brutal, feudal, murderers, Bacha Baz (pedophile) scums which gave rise to rebellion.
2) Corruption. USA gave billions and billions of dollars to Afghan government for Afghan security forces and infrastructure but they went into the pockets of Afghan government officials. Afghan population didn't saw any improvement in their lives.
3) Lack of justice. Afghan courts are expensive and takes too much time and poor Afghans cant hire lawyers with heavy fees. So they started going towards Taliban courts which enforced swift justice and increased Taliban influence more and more.
4) Opium cultivation. Taliban extort taxes on opium cultivation done by Afghan warlords. Which increased their funding more and more.
5) The killing of innocent Afghans under the guise of killing Taliban by Afghan and US forces gave rise to hatred among local populace and led to more and more recruitment for Taliban.
6) Iraq War. US started Iraq war while Afghan war was going on.
In simple words, US lost in nation building and ordinary Afghans didn't saw any change in their lives.
Last thing, why didn't US use MUTUAL DESTRUCTION policy at the end
Because US was there for nation building and hunting Al-Qaida terrorists(as they put it); not at war with Afghanistan or to destroy them.