Well Afghanistan didn't bomb USSR buildings and murder almost 3000 innocent Soviet citizens. And the USSR was attempting to subject Afghanistan to Soviet will rather than free Afghanistan from an oppressive ruling group, install some semblance of self rule, and allow the Afghan people to be able to choose their own destiny.
The US may have been naive and wrong headed in thinking the mass murder of US citizens warranted response and even more so that they should target bad guys instead of innocent Afghani citizens and/or could leave Afghanistan better than it was.
But there were very different motives involved here. The USSR got no support, well wishes, or assistance from the Afghani people. The US has.