Again, no Galactic Law worth anything would allow annexation by force just because there's a treaty. ANY conquered country has to sign a surrender which involves turning over territory to the conqueror, but that doesn't mean it's legal. You're saying if the UFP knew a Cardassian fleet had crossed into the Bajoran sector, started landing troops in the capital, etc. that they couldn't lift a finger once an annexation treaty was signed? That's ludicrous. That's an interpretation of the "law" which would clearly favor any aggressor.
Could you imagine if that were true? The Cardassians, Romulans, etc. would just be like "great, let's go conquering away, once we make the poor saps we've conquered sign something called a "treaty of annexation" the Federation can't interfere!"
The Cardassians didn't just send a fleet to Bajor and force them to sign an annexation formalization to justify it, they had been on Bajor for years. They arrived first to say "We just want to help you" and the Bajorans welcomed them, then as the years went on they got more and more controlling (coinciding with the fall of the more peaceful Cardassian civilization and the rise of the Central Command) until they formally annexed the world.
So it was a long-term situation that started out peacefully and without the military occupation, with the Bajorans formally giving them presence. Then it all went sour.