He wasn’t running for public office at the time.
And maybe we should have a law that punishes politicians for paying money to cover up affairs. But we don't have that. Trump's prosecution was, instead, a triple bank shot combining three different vaguely written laws in a combination that makes the Double Irish with Dutch Sandwich look straightforward.[1]
As CNN's head legal analyst Elie Honig explained: "The charges against Trump are obscure, and nearly entirely unprecedented. In fact, no state prosecutor — in New York, or Wyoming, or anywhere — has ever charged federal election laws as a direct or predicate state crime, against anyone, for anything. None. Ever."
https://nymag.com/intelligencer/article/trump-was-convicted-...
[1] https://en.wikipedia.org/wiki/Dutch_Sandwich