The Berlin Wall divided two different political frontiers. As Hadrian’s Wall and Offa’s Dyke were built to keep opposition forces at bay, the Berlin Wall kept capitalists and their agents out as well as forcing their own people not to venture outside the communist world where they could be contaminated by Elton John and Pink Floyd.
Defense walls are one of the most ancient products of government. Jericho had a wall since fallen to ruin thousands of years ago. North American aboriginals never used stone defense walls, except for one excavated a few years ago in North Dakota that protected a city long gone. They were an exception to the rule. Signs of fatalities existed at the wall.
Communism was totalitarianism or for some, a socialist version of anocracy. It was a form of government disliked not only by many of its subjects, capitalists hated it too. Soviet and communist frontiers were designed to defend against clandestine and conventional invasion. The Wall was simply one element in the great ideological war between Marxism and the Free World.
Not all East Berliners were non-communists. Communism had some popular support I would guess. When the 1993 White House in Moscow conflict occurred between Yeltsin’s tanks, the public and those supporting the Supreme Soviet in the White House, there was residual though not overwhelming support for communist government as theoretically it provided food to the starving as well as Dachas for the elite party members.
There have been other walls or dividing barriers placed between rival political and social cultures in modern times. One that springs to mind is the zone of rubble and junk dividing Turks and Greeks at Cyprus. The Israelis have built a wall to keep out Muslim suicide bombers, and famously, the demilitarized zone and barriers existing between North and South Korea have existed since the 1950s.
If governments and citizens of nations have no issues with one another, and if there would be no difference if a wall existed or not, in the absence of a wall, walls generally are not built.
European housing, especially in Italy, is notable for the defensive-like architecture with interior courtyards for security, that existed in pre-contemporary eras. When law enforcement was not so good, people needed to defend themselves against a world of wandering criminals, gangs and so forth.