Open borders between countries are the ideal, but they can only work successfully when wages/prices and standard of living are more or less equal and when they have the same economic and political system.
For example, it could never work in divided Germany or divided Berlin where they had totally different political and economic systems. Take divided Berlin as an example of why the Wall had to be built. People were living in subsidized rented flats in the East and commuting to high paid jobs in the Western part of the city before the Wall went up. While the GDR (East Germany) was paying reparation fees for the Second World War to the Soviet Union for the whole of Germany, West Germany and West Berlin were getting Marshall Aid from the USA. Although the GDR government rebuilt the badly damaged East Berlin, and places like Dresden, all heavily bombed in the War, and while East Germans were among the most affluent and smartly dressed in the Socialist bloc, West Germany and West Berlin was poaching their professional people. Any East German who got to West Berlin or West Germany was automatically entitled to West German citizenship. At the same time, before the Wall went up in Berlin, West Berliners were able to cross freely into the Eastern sector of the city and strip the shops of subsidized foodstuffs. Under Socialism prices for essential goods and wages were controlled and so obviously lower than in the high-priced, high waged inflation-hit Western sectors of the city, so in August 1961 the Wall was erected. I do not approve of the minefields or shootings, and think there were ways visits both ways could have been permitted (a hefty returnable deposit raised by public subscription for GDR citizens to visit the West for example), but the point is the border had to be controlled.
The same is true between all countries where there are large differences in standards of living, wages and prices. Economic migrants tend to be the richest in the impoverished countries who can afford to pay to get to the richer countries. If there is a large flood of economic migrants to the richer countries, they leave the poorer countries even worse off. In divided Ireland it is now obvious the open border only worked when both countries were in the European Union. With UK out of the EU, and the Irish Republic still in the EU, it will be impossible to maintain the open border unless the UK or at least NI stays in the Single Market and Customs Union.
The GDR suffered economically as its professionals fled West, and after Socialism in Eastern and Central Europe collapsed, so many Polish men went abroad to UK and other places that there were not enough left to operate the fire stations.
I believe every country has the right to control both immigration and emigration, based on quotas. Total freedom of movement is only possible when there is a more of less level playing field and immigration/emigration are roughly balanced, rather than a heavy flow of emigrants/immigrants one way.
The GDR regarded mass emigration as tantamount to treachery, as those professionals educated and trained in the GDR fled West. When the flow of economic migrants is large and not balanced by a flow of immigrants, there are serious problems. What is then needed as a long-term solution is to bring the poorer countries up to the level of the richer ones. This is more difficult when so many are leaving, and impossible when there are totally different political and economic systems. If things are heavily subsidized by the State, and prices and wages are controlled, then a neighboring country with a high-wage inflationary capitalist system may seem attractive, even though rents, property prices and everything else are much more expensive.
So fences and walls are regrettably necessary, but shootings, minefields and other inhuman acts like separating children from parents who cross illegally are all unacceptable. A quota system should allow both immigration and emigration. When several countries or the whole world has a similar standard of living and more or less equal wages/prices, then freedom of movement is made easier, though some control will always be needed to apprehend criminals and terrorists.