Ukraine doesn't even have to "win". They just need to drag it out long enough that Russia decides to pack it in. See Afghanistan and the many countries that have stepped up to the plate there only to go home.
The US was able to walk away from Afghanistan for the simple reason that Afghanistan doesn't matter to American security interests and never did. Still, the ongoing costs of the US occupation were low enough, and American pride great enough, that it is actually quite surprising that the US left. Trump would likely not have ultimately accepted the "humiliating chaos" of the withdrawal that he initiated, while Biden would never have had the political capital or courage to get it going in the first place, but was willing to see it through because it coincided with his skepticism of the Afghan enterprise going back to his ringside seat in the Obama administration. Really, if you go back to 2015 and roll the dice, nine times out of ten the US is still in Afghanistan today.
The costs to Russia of a prolonged occupation of Ukraine are likely to be much, much higher, but their strategic investment in Ukraine is also much, much greater. And ultimately, Russia doesn't required Ukraine to be a functioning nation any more than the US requires Syria, Libya or Afghanistan to be functioning nations. While it is probably beyond Russia to create and maintain a new stable order in Ukraine, the more limited negative goal of wrecking the place (and keeping it wrecked) sufficiently that it cannot become an EU/NATO bastion is well within Russia's capabilities.