Walls can not protect you from dhijadists either, the mortars take out the city- and besieging starves it out. In sudan- a "walled and ditched" city recently fell to the djandjhawid.. https://www.iss.europa.eu/publications/commentary/fall-el-fa...
If some trenches and an earth wall turn a short raid into a long siege, that at least gives the army some time to send reinforcements and attack the besiegers.