It was lawful. Tit. 8 U.S.C. Section 1182(f) states:
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.
Section 1182(f) authorizes the president to issue temporary bans on the entry of classes of aliens for national-security purposes.