I'm not defending it, but there is a legal basis. CFIUS[1] laws give the president authority to close down foreign businesses under certain circumstances. (This is not to say "it's completely legal" - there are a bunch of ways this could be challenged).
[1] https://home.treasury.gov/policy-issues/international/the-co...