I do indeed hold that a king who will execute somebody for something as simple as not doffing their hat is doing something evil.
But this does not mean you should not doff your hat. One bad law does not make a king a tyrant, and does not end all authority over us. Doffing the hat to the king is, in fact, not dependent on the penalty of not doing so. It is just and proper to show respect to your lawful sovereign, the man who is the symbol of your country, whose laws you live under, and who you put your trust in to lead you. Good or bad king, he is all of this whatever the wisdom of that one law.
So, no, I do not think a king should be killing people who refuse to doff their hats but, yes, I do think we should doff our hats to the king. I don’t think this is particularly hard to reconcile.