Prior to the invention of aircraft, our world's real world experience with defending a town was pretty simple. Settlements only ever had to resist attacks from landbound humans. Walls were very effective against smaller forces of humans. Armies had to travel, and siege engines had to be built and transported.
In D&D, a city wall means nothing to dragons, kaiju, aerial monsters and cavalry, or creatures that can burrow, like earth elementals used in siege warfare.
A town can only survive if they are not threatened by fantastic forces, or if they have their own fantastic or supernatural defenses. In a world of danger, the leaders would be people who actually have the power to protect the commonwealth, doing so themselves, or by being so respected that powerful heroes serve them loyally.
Without such defenses, an intelligent dragon can absolutely destroy just about any open air settlement they can can access. They can destroy the crops, water sources, trade, and besiege the town. They can make strafe attacks at night to kill wall defenders. They can get servants/allies to infiltrate, poison wells, or assassinate, or pretty much anything else.
If dragons had a habit of destroying humanoid settlements, dragon slayers would exist and hunt down those existential threats.
Cities without powerful defenders that can rival dragons are not threats to dragons. That is why dragons can, and sometimes do in the stories, accept tithes. It makes sense for some dragons to accept bribes. It would be worth trading some of your livestock to feed the local dragon. It's just business. Be useful to the dragon so it doesn't want to kill you. A very common local law could be... don't piss off the local dragon.