It's a complicated one, but legally it's a civil contract; if the Ukrainian government decided to stop the gas flowing, both Gazprom and all the companies "downstream" would be in their rights to sue for breach of contract and/or causing gas shortages, costing the Ukrainian government billions.
And you could wonder why they signed the contract anyway given Russia invaded/annexed Crimea 5 years prior, but, it's a lot of money, and at the time it was still considered a civil contract I presume.
I'd imagine the logic goes something like Ukraine believes they are benefiting and Russia is too, but they aren't sure which side is gaining more from the movement of gas through Ukraine (which, note, in real terms is supporting the economies that are arming Ukraine). In that situation, the obvious thing to do is just let things play out as contracted. If it was obvious that Russia was gaining a lot more from the deal than they are then they'd just stop.