There’s very little geopolitical advantage to Afghanistan for the US. It’s a very poor country, with a challenging geopolitical situation, on the other side of the world.
Historically it was interesting to the Mongols, the Persians, the British Empire and the Soviet Union (and the rest) because it was next door. They were expansionist empires, but even if they weren’t, all countries are affected by their neighbours.
US involvement was directly due to 9/11. The world thought that the Taliban were sheltering al-Qaeda. Look how many countries joined the coalition.
As for Iraq, combination of Saddam being a really awful man, intelligence suggesting (erroneously) that he had WMDs capable of being used, and a heightened fear of terrorism after 9/11 pushed Bush and Blair into invading.
Yes, the West generally believes that democracy is a good thing and wants to see more countries become democracies. But if the US was overthrowing governments purely so it could have a better relationship with the new government, it wouldn’t choose insignificant countries like Afghanistan. Venezuela would be an obvious one where installing a friendlier government would be hugely beneficial both to the US and to Venezuelans (if, as neocons tend to do, you ignore the human cost of the war). It also isn’t bordering Russia or China, so no concerns there.