I'm just going to ramble. My son is just turning 5 so take it with a grain of salt, although I've known a lot of kids that age.
I think the developmental task in the 5-7/8 age range is partly to stop thinking the world revolves around you (lifelong process but I mean in fundamental ways).
And I think for some kids that is really scary-making and they get fearful and shy, and for some kids they sort of ride it out, and other kids get really angry and defensive.
For me when I had close contact with a nephew that was being mean and rude I found what helped was a kind of 3-prong approach. When he was mean or rude I would say sternly but not mean/mad: "I do not want to be spoken to in that way. It hurts my feelings/annoys me." With prolonged eye contact. Then I would repeat whatever in a polite way. If he continued, I would walk away.
I did not personally find punishment helped with attitude issues because it more escalated the stakes. Although I have to admit slamming doors probably would get me tempted.
Second I would give him a chance to be the king for the 5 minutes or whatever when he was NOT being rude. Like choosing the dessert or - this sounds dumb - having the fancy plate/spoon. I think Playful Parenting has a lot about this but we did it in concrete ways 'cause well, hadn't read it yet.
Third I tried to help him express his very real lack of control in his life (his parents were divorcing etc.). With my son we generally try to avoid bad language but when he had appendicitis we told him "appendicitis SUCKS." And we let him say that as much as he wanted. I was amazed at how much that helped him. Now when he has a bad day at school I don't try to help him see the sunny side. I say "sometimes it is really hard to be in school." Maybe you are doing this but we find it helps.
I agree food and sugar could contribute too.