In the past, it was generally understood that if you had a population center then a wall should be built around it to protect it from roaming barbarians or even conventional army's. However at some point the idea of the city wall became obsolete even against the militias who do not have comparable military equipment with modern nations.
One thing to understand is that fortifications are expensive to build and, more importantly, expensive to maintain. Moreover, to remain effective, the terrain outside of the walls has to remain cleared. The city walls aren't going to do much good if the entire area up to them is covered in building that will provide cover to advancing forces. That means that walls will almost certainly constrain the city to growth within the walls and not outside them, which can drive up prices for housing and real estate within the walls. As such, you can either artificially constrain the size of the city to the area that can be effectively protected by fortifications, or you can pay the rapidly increasing costs of constructing defenses around a larger and larger territory. All this goes to say is that there are significant economic factors vying with the issue of military effectiveness when it comes to fortification of urban areas.
Now, that being said, the traditional narrative is that the classic 'city walls' you might imagine of were rendered obsolete by the widespread adoption of gunpowder siege artillery. To be effective, walls were designed for height to make them more difficult to take by storm, and provide greater advantages to the defenders atop them. However, that also tended to make the walls thinner. These thin high walls were very vulnerable to early gunpowder artillery, and so, adjustments had to be made. Walls became shorter and thicker, and fortified bastions were added that enabled defenders clear lines of fire. These star forts or trace itallienne would be the dominant form of fortification used throughout the early modern period, with the initial development of these new style of fortification found around the late 15th to early 16th centuries, and would continue to develop throughout the 17th and 18th centuries into truly massive complexes of overlapping forms of fortification. Although they do not fit with the classic image of the city wall that you might see in a fantasy movie, these fortifications were still commonly built around the city itself.
The end of anything that could be considered a 'city wall' came later. As artillery increased in power and range, with rifled guns and explosive shells, in order to protect a city, the defenses needed to be pushed further out. Rather than a fully inter-connected series of walls, a city would be better protected by 'rings' of mutually supporting fortresses. Throughout all of this please recall the ever important factor of cost; not just the cost of the fortifications themselves and their maintenance, but also the cost imposed on the city they're built around. Throughout this period, fortresses generally became less and less effective on their own, and were highly dependent on the ability of field armies to relieve them if they were placed under siege. With the declining utility of city fortifications, and the increased size of cities, city walls and city fortifications gradually fell by the wayside as their value no longer justified their costs.
To give a tl;dr: while effective gunpowder artillery was a major blow against the medieval style city wall, the styles of fortification that replaced it endured. Ultimately, it wasn't one invention or innovation that obsoleted city walls. Rather, it was a combination of new military technologies, and a changing social and economic landscape that really rendered the city wall obsolete.
Hope this helps, and feel free to ask any follow ups.