We've had a bunch of questions along this vein in the past couple of days (can't imagine why...). Here's my two bits.
There has been something of a misconstruing of Afghanistan history from the end of the Soviet-Afghan War to the rise of the Taliban, even from US politicians who honestly should know better. I'm going to try to give a concise timeline.
The Geneva Accords were signed between the US, USSR, Democratic Republic of Afghanistan (ie, the communist government in Kabul led by President and General Secretary Mohammad Najibullah), and Pakistan. The accords stipulated that the Soviets would withdraw their military forces, that Afghanistan and Pakistan pledged non-interference in each others' affairs, and that the (major) Afghan refugee crisis would be addressed by both parties. The Accords did not stipulate an end of US support for the mujahideen forces in Afghanistan (President Reagan was adamant on this point), nor did the Soviets end economic or military aid to Najibullah.
All Soviet military personnel were evacuated by February 15, 1989, and Gorbachev overrode other members of the Politburo in insisting that no further direct Soviet military involvement (such as air strikes, or keeping a force of 10,000 or so in Kabul) would occur. He was very acutely aware of the parallels with the American involvement in South Vietnam, and did not want a similar situation to occur for the Soviets.
Mujahideen forces went on the offensive, and PDPA (People's Democratic Party of Afghanistan) forces controlled only a few major cities around Afghanistan's ring road, as shown here. However, Najibullah was successful in consolidating PDPA forces, and defeated a mujahideen siege in mid 1989. The PDPA forces managed to stabilize the situation and go on some limited offensives, and Najibullah's government was able to hang on against mujahideen forces.
By late 1991, the Soviet Union was collapsing, and its foreign aid dried up. The Najibullah government was no longer able to rely on this material support. The strategic advantage shifted to the mujahideen forces, with them capturing Khost in March 1991. By early 1992, the writing was on the wall for the Najibullah government, with a major defection of militia forces under Ahmed Rashid Dostum to the mujahideen (Dostum is a real survivor in Afghanistan politics, by the way, and has managed a career spanning from Communist militia leader to mujahideen to an ally of sorts of the Northern Alliance to becoming Vice President of Afghanistan, which he was until last year - and that's all while surviving numerous assassination attempts and being implicated in war crimes for good measure). Najibullah indicated that he was willing to step down for an interim government, and the UN brokered an agreement with the mujahideen coalition to this effect, but the mujahideen forces on the ground decided to capture Kabul outright.
The capture of Kabul occurred in April, 1992, and control was divided between the forces of Dostum, Burhanuddin Rabbani, Ahmed Shah Masood, Gulbuddin Hekmatyar (another interesting character of Afghan politics - he went from US-backed mujahideen commander to warlord also implicated in war crimes to enemy of the US and Hamid Karzai and "Specially Designated Global Terrorist" after 9/11 to a member of the Afghan National Government in the 2010s - he is currently still in Kabul and criticized President Ghani for fleeing) and a few smaller forces from the coalition who for simplicity's sake we'll ignore for now.
Fighting more or less immediately escalated between Rabbani and Dostum on one side and Hekmatyar on the other, with Hekmatyar launching numerous Scud missiles against Kabul and earning the sobriquet "Butcher of Kabul". Much of the destroyed ruins in Kabul that could be seen during the Taliban's rule in the 1990s and even in 2001 came from Hekmatyar and the early 1990s infighting between the mujahideen factions. Rabbani became the president of the internationally-recognized government, but the various factions continued to fight with each other in Kabul and elsewhere.
Around 1994, the Taliban began to form as a political and military force. They were largely (but not exclusively) ethnic Pashtuns, who mostly inhabit southern Afghanistan, and the Taliban themselves were organized out of religious students (hence their name, as talib means "student") among Afghan refugees in Pakistan. The breakdown in national order and fighting among the warlord factions meant that national governmental services were largely nonexistent, and the Pashtun areas of Afghanistan were mostly under control of very local authorities. The Taliban under Mullah Omar captured Kandahar in November 1994, and moved to gain control of much of the rest of southern Afghanistan, with the backing of Pakistan's military intelligence, ISI. By September 1996, the Taliban captured Kabul, and publicly executed Najibullah (who was still in the city at the UN compound). Control of Afghanistan roughly looked like this, with the Taliban now in control of most of the country, and the regions remaining outside their control mostly being controlled by Dostum and Massoud. These forces opposing the Taliban organized themselves into a rough coalition known as the United Islamic Front for the Salvation of Afghanistan, or Northern Alliance.
The Taliban would continue a series of hard-fought offensives in the north of the country against the alliance in 1997-1998, with major battles being fought around Mazar-i-Sharif. These saw local commanders turn against Dostum to cooperate with the Taliban, Dostum flee the country, and a number of Iranian ambassadors in the city to be murdered, almost leading to war between the Taliban and Iran. Numerous massacres occurred during these campaigns, especially at the hands of the Taliban, who slowly secured contorl over more of the northern part of the country. Massoud continued to fight the Taliban from his Panshir Valley home, until being assassinated by al-Qaeda operatives ... on September 10, 2001.
So: it was a very twisted path from Soviet withdrawal to the Taliban takeover of Kabul, with the two events separated by more than seven years. It was an even more twisted road from there to 2001. I think an important takeaway is that many, if not most, of these political figures have remained prominent in Afghani politics to this day. A lot of the Taliban's control in 1996-2001 depended on local figures and warlords broadly either being in alliance with the Taliban or against them. My limited understanding is that much of the Taliban's offensive this year has also relied on local agreements, and so it remains to be seen just how unified Taliban central control over the country will be.