What purpose did the wall around a city serve?
Depending on the context and who built the wall, it was usually to keep the residents of the city inside the city, OR to keep people outside the city outside / stop the influence of people outside the city from entering the city.