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.
Ultimately the general public is capricious in its beliefs: cutting the gas off and causing energy prices to spike in Europe means someone will call for the head of whoever's nearest to blame.
Ukraine also was deliberately not targeting Russian oil assets earlier at the request of the US for economic reasons - though I'd say recent American political history shows what a mistake that is.
There's been a change in the administration (and therefore strategy) of the USA, which changed the way the game was being played.
I think that (almost) everyone that has actual skin in that particular game also knows that none of the agreements that any of them make are reliable for a long term (I saw recently that the Ukranians gave up the Nukes they had at the behest of the US government, and on the.. I don't know if it was explicit, implicit, or just assumed.. understanding that the USA would provide some sort of security guarantee (which, of course, has never materialised)
They also had about as much latitude to keep those nukes as Germany would. Some people act like Ukraine owned and controlled the nukes and had a meaningful choice. They never did.
It wasnt given security guarantees either, it was given a promise that its independence wouldnt be infringed upon in a memorandum (not in a treaty).
As the Americans stated themselves in 2013 when they violated their promises within the Budapest memorandum, that memorandum wasnt legally binding. It was treated like toilet paper first by the Americans in 2014 and subsequently the Russians in 2014.