Well, according to urban legend (and actually proven to be untrue, but whatever), the reason Spain went for a broader gauge was to make it more difficult for the French to invade. Well, the French didn't invade but the track gauge didn't come into that decision.
Having a different gauge didn't stop the Germans invading Russia in WW2 and didn't stop the counter-invasion of Russia into Central Europe.
So at the end of the day its a feel-good symbolic thing that doesn't stop invasions. The question is should a war-torn poor country be channeling big money into feel-good projects?
Finland also shares broad gauge with Russia for historic reasons, but nobody doubts those reasons are in the past, and as far as I know, nobody is asking to change the gauge for emotional or military reasons.
Finland also doesn't have cross-border links to Sweden or the rest of Europe. (Well, OK, one link in the far north which is economically impractical to use.)
Yes, so the two reasons for the gauge change:
(1) Russia actually did plan to use Ukrainian Railways for their military logistics. In Donbass, when they invaded in 2014, they did and still do use seized Ukrainian Railways for their logistics, and they are doing so west of Mariupol too. Ukraine blew a bunch of bridges near the border to prevent Russia from doing so in the rest of Ukraine during this invasion. Belarussian partisans who oppose Lukashenko did the same thing at the Belarus-Russian border. Having standard-gauged tracks will be a permanent defense against this.
(2) Ukraine is obviously not going to have significant interchange traffic with Russia for years to come. The war, the war crimes, and the looting has created a seething anger at Russia from ordinary Ukranians. And I don't think the situation will resolve quickly even after a peace deal-- consider that the Armenia-Turkey border has been closed for decades now. But Ukraine WILL have ever-increasing interchange traffic with Europe. There are multiple railway border crossings already: 5 with Poland (plus a 6th out of use), 2 with Slovakia, 2 with Hungary, 2 with Romania (plus a third out of use), and 2 more from Modolva to Romania. The gauge changes are seriously hampering integration with the European system and slowing down traffic. It's an economic development move to switch to standard gauge.
Most of Ukraine's railways are very modern but they still mostly use wooden ties. Changing the gauge is less of a nightmare than it is with concrete ties. And it's making it narrower, which is always easier than making it wider.
The big issue is having to regauge all the existing rolling stock, of which there is a lot. But Ukraine is motivated now. Might not happen. But it might.
It doesn't really make a difference with ordering rolling stock (all the major manufacturers can supply you with bogies of different widths) but it makes a big difference if you want to run trains -- both freight and passenger -- direct from Kyiv to Vienna or Warsaw, and they absolutely do want to do that.