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.