The Supreme Court has held that this applies to criminal law - you can't change the punishment of a crime or change rules of evidence to convict someone who was acquitted.
You can certainly pass laws to undo a merger or (equivalently) break up a company.
The problem's not the "ex post facto". The problem is the "Bill of Attainder". You can't pass a law that, e.g., breaks up Amazon - to do so would be to deprive them of property without trial.
But you can create a law that Amazon (and potentially others) will be in violation of, and following proper trial, they are broken up.
You can certainly pass laws to undo a merger or (equivalently) break up a company.
https://en.wikipedia.org/wiki/Calder_v._Bull