There is much confusion about why the USA and UK were even in Afghanistan, to begin with.
Afghanistan has been occupied by British and American forces since 2001 after the US military invaded the country post 9-11to dismantle Al-Qaeda, who took responsibility for the terrorist demolition of the Twin Towers. The UK supported the invasion as an ally.
When this September invasion happened, the Taliban led the government of Afghanistan.
Then-President George W. Bush demanded that the Taliban expelled Al-Qaeda and extradited Osama Bin Laden. The Taliban declined to do unless proof of Bin Laden's involvement in the 9/11 attacks could be proven by the USA.
The USA rapidly set up military bases around Afghanistan.
On November 12, 2001, the Taliban abandoned Kabul and it was in the handed over of coalition forces.
At this point, other major Taliban positions began to fall, the stronghold was sieged, and the remaining Taliban fighters were ford to retreat to southeastern Afghanistan, considered the birthplace of the Taliban movement.
Military efforts by UK and US forces continued across Afghanistan to dissolve the Taliban. In December 2001, the UN hosted the Bonn Conference, wherein four Afghan groups participated, and created the Afghan Interim Authority to return Afghan sovereignty.
On December 20, 2001, the UN authorized the introduction of an International Security Assistance Force, an international body of Governments to support the Afghans' security in Kabul and surrounding areas.
This Government remained in force until August 14, 2021, when the Taliban seized Kabul following a lightning military campaign.