They were discussing this on The World Tonight earlier. The commentator being interviewed said that maintaining the US Pakistan relationship was a far greater priority for the US than Afghanistan.
Neither the Afghan government nor US troops can control the Taliban unless they control their safe havens in Pakistan and the US knows the Pakistani government won't/can't do this.
I feel awful for all the people in Afghanistan, especially women because their lives are so constrained. Many years ago, I saw a documentary about Afghanistan before the West colluded with the Mujahideen and other militants after the Russian invasion to overthrow the communist government which had close links with the Soviet Union. The communist government was by no means perfect but it did introduce huge literacy programmes and made forced marriage illegal. Whatever its flaws, I know which regime I'd prefer to live under.
As Barbarianmum says, so many different powers have invaded Afghanistan because of its strategic position. It goes back further than the last few hundred years. Even Alexander the Great tried.