The invasion of Afghanistan was clearly motivated by revenge, as the US invaded quickly without a proper plan or debate. It wasn't that catastrophic in itself, as the world generally considered the invasion justified. But it made it easier to invade Iraq without a proper plan or debate, which was catastrophic.
Among other things, the invasion of Iraq taught the world that invading other countries with false justifications was perfectly fine. Putin certainly learned that. Then the US went on to alienate its traditional European allies that refused to participate in the charade. To many European politicians at that time, Putin didn't look much worse than Bush. When the US tried to warn Europe against tighter economic integration with Russia, those politicians refused to listen. When Putin turned out to be much worse, there were too many vested interests to reverse the course.
Also, I don’t necessarily think it’s fair to blame the Iraq War for some European countries being all squishy towards Russia; they’d been doing that off and on since the Cold War.
The norms that govern international politics are similar to the ones that young kids develop when left to their own devices. Without shared values and without an authority that can impose theirs, you can't evaluate justifications. The norms that emerge deal with the actions themselves. You can do X for your reasons if I can do X for mine, and so on. The ways the US used their global hegemony taught Putin what he can do for his own reasons.
It's easy to forget how immensely unpopular the Bush administration was among the West European elite. Obama got a Nobel Peace Prize for not being Bush, while Biden didn't get one for not being Trump. When the Bush administration tried to tell Europe not to deal with Russia, they had barely more credibility than the Iraqi propaganda guy.
That loss of soft power was the beginning of the end for the American hegemony.
I would diagnose it differently. If all the US looked for was revenge, we could have been in and out of Afghanistan much more quickly and accomplished the mission. The mistake in Afghanistan was to engage in a poorly conceived twenty year experiment in nation building.
If anything the problem is that Americans are too isolationist to take the duties of hegemony seriously. There’s really no reason we couldn’t occupy Afghanistan in perpetuity if we actually cared to bother, but it became politically unpopular for some reason. Maybe because we were never honest with ourselves about what we were doing.