INA 1182(f) is pretty clear;
*(f) Suspension of entry or imposition of restrictions by President
Whenever the President finds that the entry of any aliens or of any class of aliens into the United States would be detrimental to the interests of the United States, he may by proclamation, and for such period as he shall deem necessary, suspend the entry of all aliens or any class of aliens as immigrants or nonimmigrants, or impose on the entry of aliens any restrictions he may deem to be appropriate. Whenever the Attorney General finds that a commercial airline has failed to comply with regulations of the Attorney General relating to requirements of airlines for the detection of fraudulent documents used by passengers traveling to the United States (including the training of personnel in such detection), the Attorney General may suspend the entry of some or all aliens transported to the United States by such airline.*
https://www.law.cornell.edu/uscode/text/8/1187 is also worth reading as it specifically blocks people from certain countries.
I have read *legal analysis" that says what he did was legal and others that have said it was not. Both cite the same law!!!