Taking “the town” to mean its people in “ask the town” can also be discussed in terms of semantic figuration. The present technical use of majāz, however, emphasizes how “al-qaryati” can be analyzed as changing from genitive to accusative. These are not interchangeable explanations.
Explaining that “the town” refers to its inhabitants answers a question about meaning. It does not by itself explain the contrast between the reconstructed genitive noun and the expressed accusative object. That requires the omitted head and new syntactic position.
A single passage can legitimately invite more than one analytical perspective, but each perspective must answer its own distinct question.