At that point the Federation and its allies were already winning the war. The virus was no longer about preserving the Federation, but just murdering the leaders of the Dominion. The Federation was just as bad as Section 31 for refusing to give the cure.
They didn't refuse to give up the cure, they just wanted to use it for leverage. They ended up exchanging the cure for an end to hostilities. Everyone gains something then.
And, honestly, why is the Federation expected to be so altruistic that they'll hand over a valuable cure to a dangerous enemy without expecting anything in return? The Federation exists to protect its own citizens, not to protect everyone else.