The Kingdom of Didd has feudal written, and drawn, all over it. It has a King, knights, magicians, and everyone dresses like they work for a traveling renaissance faire. But even though the setting is totally fairy tale, the denizens of Didd don't seem to have to deal with typical fantasy hassles as orcs, wizards, or dragons—at least not on the reg. As such, they're fairly flabbergasted when Bartholomew Cubbins's hat starts going all magic trick.
The Kingdom of Didd has a very strict social hierarchy. It's so strict that the city planners had to physically construct the city to match it:
[King Derwin's] palace [stands] high on the top of the mountain. From his balcony, he look[s] down over the houses of all his subjects—first, over the spires of the noblemen's castles, across the broad roofs of the rich men's mansions, then over the little houses of the townsfolk, to the huts of the farmers far off in the fields. (2)
It's less a social pyramid and more a social mountainside. As the story progresses, we see the class structure of Didd mirrors its urban planning. The King is on top, then the noblemen like Duke Wilfred, the rich men like Sir Snipps, the townsfolk like Yeoman the Bowman, and lastly, the farmers like Bartholomew and his kin.
The rigid class structure extends to the rules and laws of the society. Since Bartholomew is but a lowly farmer, and the King is top of the tippy-top, he can arrest the boy simply for not taking off his hat in the King's presence (37). And do the citizens of Didd think this is odd? Yes, but not because the King had the boy arrested. Instead, they can't believe some boy "'won't take off his hat'" (46). The nerve of some people.
And that's how the setting of Didd helps set up the odd tale of how any entire Kingdom fought to remove a hat from some poor boy's head.