Taliban just won by hiding amidst its people, by bribing, by intimidation or just via simple family relations for the 2 years that US occupied it very much the same as how the Vietcong did in the jungles during the Vietnam War. You never win when you fight a war on someone else's turf. No matter how sophisticated you think your satellites, your GSP, your drones are, you will never be able to win over somebody who grew up in those jungles, in those deserts, on those mountains, in those alleys. To us, these Talibans are terrorists but to some of those Afghan local people, they are their brothers, fathers, sons, cousins, uncles, friends and that's bonds that you could never break and that's what those Talibans used as their shields to just basically wait out until the west is all exhausted and broke and now they come out and just take over everything.
Bottom Line: Never ever NEVER ever go fight in a war 1) on someone else's turf and 2) in a culture that you have no idea about and in a language that you can't even understand without interpreters. I thought the US would've learned this lesson after the Vietnam War, the Korean War but no obviously the US still has still not learned it with this war against the Talibans.