One may see similarities in the two situations and think the west reacted differently, but in reality the situations were different.
The Taliban government was supporting terrorism by refusing to hand over the terrorist leader Osama bin Laden (and I think we all recall the Twin Towers incident in which he was a prime cause). Consequently the Taliban were attacked and removed as an unacceptable power in the world. But the west, whilst withdrawing prematurely, and without US consultation, nevertheless had to go at some point. One can not occupy, for the benefit of the population there, forevermore. However there is no parallel with Russia/Ukraine which is clearly just an empire building grab by Putin excused by nonsense from their apologists.