To be honest, America has given Afghanistan a lot.
We don't realise it, but Afghanistan's basic history is...
1) The Soviet Union invades Afghanistan and establishes communist authority, which is reviled by most Western and Muslim countries.
2) Infiltrates Mujahideen, which are supported by the US and trained by Pakistan.
3) The USSR is vanquished, and the US withdraws from the scene, leaving a power vacuum.
4) Mujahideen funding ceases, and the group begins battling amongst itself for control of Afghanistan. New Warlords appear on the scene, spreading chaos. they imposed a heavy tax on common citizens to travel from one part of the city to another, and rape, kidnapping, and murder were all part of the daily routine. According to the Taliban, about 200 people were killed every day in Afghanistan when they took over.
5) The Taliban arrive, and opium production is reduced to virtually zero, rape cases are almost non-existent owing to fear of being stoned to death, and the total number of murders per day is greatly reduced.
But there was one major issue. They lacked fundamental financial, judicial, bureaucratic, and policing infrastructure. They had no banks, no foreign investment, no international recognition, and, of course, they were occupying the country by force, so they didn't have much public support except pushtoons. They had no understanding of human rights and their leaders were clearly not educated enough, probably that is why they were still called "Taliban" (students). I have always called them "Jungli" people... they were IMO cavemen by habits
In the last 20 years, the United States has not only raised the army (which has since vanished) and the police (some of whom are still on the job), but also civil service, infrastructure development, primary to higher education, democratic values, and worked in every sector that could help them transition from the tribal world to the modern world.
The major issue with Afghanistan, in my opinion, is that they have been at war with several countries for the past 200 years. Most countries in the globe were ruled by kings in the 19th century, but the United Kingdom established its form of democracy throughout the colonial era, and many countries followed suit, but Afghanistan was unable to progress naturally and still adheres to 19th century norms.
So, in conclusion, there is no justification for foreign invaders, and the United States was going to leave this land one day, but they have done a lot of good things at the same time, and Afghanistan has changed dramatically, and they are no longer stuck in the past as they have been for the last 100-200 years.