Yes, the U.S. military withdrawal from Afghanistan was the right thing to do, and there are three reasons why.
First, the United States had achieved its goals. The George W. administration had set out to dismantle al Qaeda, the perpetrators of the 9/11 attacks, and that was done within weeks of the invasion in November 2001. If the Bush administration had stuck to its initial goals and withdrawn, then that would have been a “victory.” Instead, by changing the goal to “nation-building” President George W. Bush set the stage for endless war
Second, the U.S. government was in Afghanistan to ensure that it would not become a haven for terrorist groups that want to attack the U.S. homeland ever again. This goal was also achieved after al Qaeda dispersed. While there are several militant groups operating in Afghanistan, such as Islamic State Khorasan and the Haqqani Network, neither of them has global aspirations that involve attacking the U.S. homeland. Also, all open-source U.S. intelligence assessments claim that al Qaeda is no longer powerful enough to plan and execute another 9/11-ish attack.
All of this is related to the third and final reason, which is that since the United States did not/could not/would not define “nation-building,” the only smart choice left was to withdraw. This notion of nation-building is also inherently racist and neocolonial, based on the assumption that there is no “nation” in Afghanistan, when of course, that is not true. The Afghans are a proud, multi-ethnic, multi-lingual, and multi-religious nation that has been a victim of great power politics and empire since the 1800s.