Catholic teaching has always been clear about the right of the state, or a country. It is based on the natural law and has a right to its existence and independence just as an individual has its own right to existence and independence. No state has a right to destroy another state's independence by any means, including sending mass amounts of people across its borders. Just as an individual can protect itself from harm from another, so can the state. It has a duty to do so for the sake of its common good. This is why countries across the globe have immigration laws.
What constitutes an attack on a sovereign state? Many things, such as all out war, sedition, treason or any societal upheaval by foreign states or individuals. That means if other nations outside a sovereign state send a number of people to cross its borders which cause societal upheaval, then the state has the obligation to protect its social order and stop them from coming in. Despite what we are hearing from many in the Catholic hierarchy today, there is not any Catholic teaching that says a state must let everyone across its borders. To do so presents many risks to those already residing in the state who have rights. Just look at France, the UK and Germany. Social unrest exists because of poor immigration policy. If you compare them to Hungary and Poland there is a clear difference in their social order. Poland has chosen to act for the common good of its society, while France has clearly not done so.
A country's citizens have a right to their own property, health, freedom to worship God and a right to act in charity by their own freewill. Letting hoards of people across the border without conditions as many are calling for, is to put citizens at risk for disease, crime and other disruptions to society. The state has the duty to enact legislation that is best for the entire common good of the country to protect its citizens rights. This is Catholic teaching. Catholicism has always taught that one must have a love for country and that it "is a virtue akin to piety or love of parents." (Right and Reason 437) So contrary to what we have been hearing out of the Vatican these days, patriotism or rightly ordered nationalism is not evil. Yes, patriotism or nationalism can go too far if one takes the state to be above the common good of its citizens. So an exaggerated nationalism that hates all foreign people would obviously be immoral. The state exists for promoting the common good for the social order of man. This does not mean however that the state must be involved in every aspect of the common good. The Church teaches the ideal of subsidiarity, which means that whatever the lowest level of society that the issue can be addressed at, should be done at that lowest level. The national state for example does not have to provide free food or free healthcare for everyone. This can be done at a local level, traditionally by the Church.
What about migration? Migration implies a continuous geographic moving of people or animals. As great as this is for birds, this is not how man was created to live. Man is created to live in a stable society, not as wondering nomads akin to locusts devouring the earth as it moves across the globe. This means that people should strive to live in one state or country and adopt its social order. When a person chooses to live in another country other than the one of his or her origin it is called immigration. That means that the individual chooses to adopt the societal conditions of the state they have chosen to immigrate. It would be immoral for the state to allow people to enter into its society who do not want to adopt to its societal way of life. It is also immoral for a person to come into another country and choose to oppose its general societal governmental structure. This is anti-patriotism and this is a vice according to Catholic teaching. This obviously includes those obstinate individuals who come from Islamic states who attempt to overthrow the US judicial system for their own Sharia law. Those politicians and judges who are allowing this are committing grave evil.
What about immigration laws? There is nothing wrong with allowing people to immigrate into a country guided by proper regulation that is ordered to the common good. For example, immigrants must not have untreated infectious diseases that can harm the current society. Criminals must not be allowed to enter. That being said, the majority of people who want to move out of Mexico for example, are legitimately looking to improve their way of life and should be able to apply to come into the US. Currently the US has laws on the books make it expensive and difficult for people to immigrate. A state has the right to make its own laws as it sees fit to protect the common good. I personally believe the current laws can and should be changed to make it easier and less expensive for upright immigrants to come into the country. The problem is that the current political parties in power want to use these people as political weapons to keep them in power and malign their political opponents.
In closing, every sovereign state has a right to its independence and its own common good. A state is not obligated to let unchecked hoards of foreigners to come over its borders for a variety of reasons already presented above. Patriotism is not bad, its a virtue, and we as patriots should look for ways to make our society better including allowing upstanding immigrants to come into the country under a reasonable regulation. One may ask, what about charity and feeding the poor. This can and is being done outside our borders on a daily basis. Of course there is nothing wrong with doing it on our own soil provided it is done morally and orderly. If possible a society should help the poor. This however must not be forced on people by the state as Socialism and Communism attempt. There is no law given by God that says a state has to let everyone across its borders to feed them or provide them with medical care using its citizens money. The Church in its mission has always fed the poor and provided medical assistance to the poor in most countries across the globe. This is done by man's freewill and through charity as God intended. "For the poor you have always with you: and whensoever you will, you may do them good..." (Mark 14:7)
Main source: Right and Reason- Austin Fagothey 1967
Saint Benedict feeding the poor.