Ukraine gov't specifically asked for it, publically. And of course, Russia government responded with anger. "Publicity" is naive. Unquestionably what Elon is doing now is provocative to Russia (and the handful of pro-Russia countries), but at a time when most places don't want to be friends with Russia, it's great PR but more importantly, it has real effects for people on the ground. It sends materialistic support and and condemnation which encourages others to follow suit.
Do you mean the most important thing for SpaceX? Because it's also important for Ukraine not just to win on the technological front but also to seem like they're winning, and bragging about capabilities helps their propaganda effort. "We have a network you can't easily disconnect or jam, and your invasion is being livestreamed on YouTube right now" might even have the effect of discouraging some war crimes from happening. If there's even a slight positive impact it's worth it.
I hope these network terminals get used, but the messaging is important too.
Just like with the Thai cave rescue.