Public opinion on this issue is sharply dividedWhen a controversial figure like Trump becomes popular and gets voted into office, the first question to be answered is WHY. It almost always signals that there is an issue in society which the previous administration has failed to deal with adequately, or that a large section of society feels is not being dealt with properly. Immigration has become such an issue, and not just in America, by the way.
The illegal immigration from Latin America is something that Trump thinks he can stop in its tracks by building a wall along the Mexican border. That, many people feel, would be a way of dealing with that problem. Legitimising the many 'latinos' in the USA is not held as acceptable, and there is a lot of irritation in the USA, as I understand it, about the multi-lingual options on government phonelines.
The second aspect of immigration is intermingled with the Muslim contingent of migrants or refugees (lumped together in one category by many). Since the 9/11 attacks on the WTC in New York, there has been a lot of hostility against Muslims in the USA - and this is what I mean by high emotions - and not just in the USA. Every time there is another terrorist attack, claimed by people who say (!) they're Muslims, the flames of hostility are fanned. Trump's edict against immigration from certain Muslim countries is designed to allay those fears.
The president feels that his loud protestations that he is acting in the best interests of national security justify all means and methods. The judiciary see fit to disagree.