اسْأَلْ أَهْلَ الْقَرْيَةِ ← وَاسْأَلِ الْقَرْيَةَ
The understood expression “ask the people of the town” is reduced to an expressed sentence in which “town” receives the accusative case.
In the first construction, “ahla” is the accusative object of the imperative, and “al-qaryati” is genitive because it completes the annexation. Once “ahl” is unexpressed, “al-qaryata” fills the object position and becomes accusative.
Both this example and “jāʾa rabbuka” involve omitted annexation heads, but one resulting noun becomes nominative and the other accusative. The new case depends on the syntactic position, not on deletion alone.