Just because you don't like it doesn't make it illegal. The Immigration and Nationality Act gives him this power.
But the president ignores the fact that Congress then restricted this power in 1965, stating plainly that no person could be “discriminated against in the issuance of an immigrant visa because of the person’s race, sex, nationality, place of birth or place of residence.” The only exceptions are those provided for by Congress (such as the preference for Cuban asylum seekers).
https://www.nytimes.com/2017/01/27/opinion/trumps-immigratio...