Although affairs are not morally right, there is nothing illegal with Trumps legal agreements with the two women.
We don’t know there were affairs. False claimants are often paid a small sum (small to a billionaire) to stop lying to create a scandal which damages the brand and costs the business more than the settlement. That is standard operating procedures both for companies & high net individuals.