Whether or not it's illegal is typically determined a few months after the act in question.
Since 2024, SCOTUS has sided with Trump about 90% of the time, so most likely it's legal.
Still, even if it's later determined to be illegal, since the law presumes the president has legal immunity to all crimes committed in a presidential capacity, there's no legal risk, so the damage can be done long before the court makes it illegal. For example, Trump's global tarrifs were determined to be illegal a year after the fact, long after the damage had been done.