It isn't illegal. It is in fact legal. What do you call a pay me or else? But it is not illegal.
It was not the only one he paid, which later, was proved a lie. But Trump paid for that to go away too, rather than pay to go through court, which more than likely would have cost more than the NDA.