Building and maintaining can be got around with magic. Manning the walls is another issue. Perhaps much of the town's construction is underground (if monsters can live in "dungeon complexes", why not humans in such super-basements?). Considerable grass inside the wall makes sense if the population is expected to move livestock into town for protection. The cost isn't so important if the wall costs are reduced through magic use... at least until population pressure drives construction on that available land... which is again less tempting if underground construction is possible instead.