After we have left Afghanistan, the Taliban will grow stronger, and, sooner or later, either 1) the government in Afghanistan will reach an accomodation with them, until ultimately the Taliban, in some form, simply take over, or 2) the Taliban will win outright.
Thus, to win the war in Afghanistan, all the Taliban have to do is survive until America pulls out.
This, they are accomplishing.
The reason for this is that the Taliban's powerbase is not being effectively attacked.
The Taliban powerbase is in Pakistan.
Pakistan has long defined itself by its Muslimness, as opposed to Pakistan's main potential enemy, India. India is, of course, larger, and would presumably prevail in a conventional war, if that war were allowed to play out until one side or another achieved absolute victory.
Pakistan has tried to offset India's advantages in various ways. For example, Pakistan long sought, and finally developed, its own nuclear weapons (though there is a story behind this, which winds its way into China and all the way back to espionage at key US facilities).
But, a main way in which Pakistan has sought some leverage against a presumed Indian victory is by means of militarized Islamic schools, called madrassas. Madrassas have been prevalent in the Islamic world for centuries, but in Pakistan they took on a peculiar twist, serving as military training centers for jihadists who would fight the infidel world. Of immediate concern has, of course, always been India; graduates of the madrassas could be expected to fight a guerilla war should India ever overrun Pakistan in a conventional war, ensuring that a conventional Indian victory would not be the last word in the conflict. However, once trained and indoctrinated into the ways of Islamic holy war, such militants are hard to keep on a leash.
For years, Pakistani-trained militants have crossed into Jammu and Kashmir, conducting terrorist attacks against Indian forces there. Pakistan has for years been a state sponsor of Islamic terrorism.
When Afghanistan fell into chaos in the wake of the Soviet withdrawal, these Pakistani-backed militias went into Afghanistan and stabilized it under Taliban rule.
Once established in Afghanistan, these jihadists slipped off their leash, seeking war against all infidels and against all Muslims who oppose the jihadists (whom the jihadists refer to as takfir); their jihad took on a life of its own.
First of all, under the Taliban, fellow jihadists found they could use Afghanistan as a base of operations against any infidel enemies, without so much as the minimal restraints placed upon them by Pakistani sponsors. This is why we invaded Afghanistan in the wake of 9/11 - to oust the terrorists that were based there under Taliban rule, and who had attacked the United States.
Additionally, Pakistani-trained and -based jihadists have continued attacks against India, as well.
However, most significantly for Pakistanis, these jihadists are not going to settle for less than victory against all infidels and takfir, worldwide, and that starts with takfir closest to home - Pakistani Muslims who do not support the violence.
Pakistan has been pulled in two directions. There is of course the Islamic militants. But, there is also a modern society in Pakistan, a Muslim society that fits peacefully into the world around it. This segment of Pakistani society is, of necessity, targeted by the militants and those who support them. For the militants to win their global jihad, the "Land of the Pure" must be cleansed of these corrupted takfir elements.
Pakistanis have at least tolerated (and significant elements of Pakistani officialdom have actively helped) the growth of militant Islamic extremists in Pakistan as a counterweight to India. This counterweight was powerful when the Taliban ran Afghanistan. However, it is now out of control, and now less extreme elements in Pakistani society may find that they get roasted in the fire they have allowed to be kindled.
The invulnerability of the Taliban's base in Pakistan is why the Taliban have not been extinguished in Afghanistan; it is why American troops have not yet come home victorious.
The base's invulnerability lies in the fact that it is on the other side of the Durand Line (the border between Afghanistan and Pakistan).
Understandably, Pakistan does not want US troops crossing the Durand Line into Pakistani territory to attack the militants; Pakistan is a sovereign nation, and the views of its people and government should be respected regarding Pakistan's territorial integrity.
However, assuming the political will exists in Islamabad to clean out the Taliban strongholds, these bases can be difficult to get to from Pakistani territory.
That political will needs to exist in Islamabad, because the Taliban will not compromise; their version of Islam means they will fight to the death against all takfir, and takfir is anyone who disagrees with them, and that most emphatically includes moderate or Westernized elements of Pakistani society.
If that will does not exist in Pakistan, then Pakistan is with the terrorists, and needs to be treated as an enemy of all civilized nations.
However, any society has its criminal element, and Pakistan should not be condemned because of its criminal element, even though that criminal element has strong support in Rawalpindi.
There is an answer that will allow for the civilized world to prevail over the terrorists, and for civilized Pakistanis to retain control of their great nation, while maintaining Pakistani territorial integrity against infringement from foreign troops.
In conjunction with Afghanistan and the US and international forces in Afghanistan, Pakistani troops need to be brought into Afghanistan. From there, Pakistani troops attack across the Durand Line into Pakistan, while simultaneously more Pakistani troops attack from deep inside Pakistan into the border areas. Across the border in Afghanistan, Afghan, US and international forces will conduct their own offensives toward the Durand Line, but not crossing it. Military operations against the Taliban on Pakistani soil will be conducted exclusively by Pakistani troops; any exceptions to this will be at the behest of Islamabad. Taliban militants will be caught in the middle, their bases will be sandwiched out of existence, and the militants will be exterminated or scattered.
On top of this, Pakistan needs to shut down all terrorist training bases in Pakistani territory, not just the ones in proximity to Afghanistan, and Pakistan needs to work to end terrorism from Pakistani territory. Pakistan needs to do this to keep from being overrun by the militants Pakistan once saw as insurance against India.
Once Pakistan has accomplished this, the international community needs to help promote peace between Pakistan and India, including offering guarantees of Pakistan's existence and territorial integrity.