Edited to Add: Howdy and welcome, Instapunderati! Thanks for stopping by.
Old-World cities had walls. That was part of what defined a city – it could defend itself. Its residents had a duty to defend it as part of their being citizens. (And I’ll note that this applied to women as well, at least in some of the Imperial Free Cities. Women who had the right to do business on their own also had duties for defense.) A city without walls wasn’t a real city, it was just a place where a lot of people lived at the mercy of any group of armed men who happened to be passing by.
There was absolutely nothing wrong with limiting access to the city. If you were outside the walls when the gates closed, too bad, come back tomorrow. If you did not have a reason to be in the city when the gates closed, then out you went. In some cases, even the Holy Roman Emperor had to ask permission to hang around, and if he got cross-threaded with the city, well… Ask Maximilian von Habsburg about his adventures with Bruges. When bad times came, those who were not citizens of the city got the short end of the stick. Those who had citizenship rights benefitted from those rights. They were also expected to do their part to help others, especially if they were well-off, but charity and open gates were not granted to everyone.
And some people went a little farther than just putting a nice wall around their city.
The reason for thinking about walls is this: http://www.scifiwright.com/2017/06/last-crusade-strangers-and-sojourners/
As Mr. Wright’s commenters point out, even the New Jerusalem in the Book of Revelation has walls and gates, as the great Gospel song puts it “Twelve Gates to the City.” Yes, this is because back when John wrote down what he saw, all real cities had gates, so of course the city of the Most High would have walls and gates. But there is nothing immoral about walls and gates and borders. In fact, if you look at common law, walls and gates are part of preventing “public nuisance” and temptation. There was a greater penalty for stealing something from behind a wall (or locked doors) than from picking it up from an unguarded and open area.
Humans make borders and walls. This is mine, that is yours. These are the city limits, the laws are different here than they are in the county. My country starts here and has these laws about who can come and for how long. Your country starts there and you can decide for yourself who stays. It goes very far back and there’s nothing unnatural about borders and lines and walls.
I’ve noticed that the open-border advocates have stopped calling the idea of putting walls on certain parts of the US-Mexican border “tantamount to rebuilding the Berlin Wall.” I suspect 1) they got bored and found something else to complain about and 2) enough people reminded them that the Berlin Wall existed to keep people in who desperately wanted out, not the other way around.
In part because of Berlin and East Germany and the Iron Curtain, today we tend to see walls as less-than positive. In the Middle Ages and Renaissance, heck, up through WWI, walls were a good thing. Bad guys were the ones who made you tear down walls – Louis XIV, Cardinal Richelieu, Napoleon – those types. Walls were shelter, and safety, and security. Walls defined where the rules applied and to whom. Walls let you tell would-be conquerors to go jump in a lake (provided you were willing and able to defend yourself and sit through a siege.) Nobles had to respect a free city with walls, and to allow its residents to live as they chose within their walls.
If you look at what is happening in Europe today, you see people considering walls, building fences, and demanding that their borders and laws be respected. Hungary, Slovakia, the Czech Republic, Poland, Austria, they have looked at Germany and Brussels and said, “No. Our laws, our land, our borders, and our option to let people in or to keep people out.” Those happen to be countries that know from recent memory what happened to places without walls, without strong borders and defenses. 1683, 1939 were not all that long ago in national memory.
There’s truth to the saying Robert Frost quoted about “Good fences make good neighbors.” A medieval city without walls was not a city. It was a target, or the property of a lord or bishop (who probably put a wall around at least his part of it.)