This is a great question because actually Huck changes in his attitude towards the Duke and the King as he develops in his own moral understanding of the world and what is right and wrong. It is important to realise that the Duke and the King and the various scams they come up with allow Huck more of a chance to see the evils of civilisation and the gullible nature of humans and also the way that humans act towards each other in negative ways, all of which contributes to Huck's character formation.
When the Duke and the King first come on the raft and show their true colours by establishing their royal identities, Huck begins by deciding to take the path of least resistance:
It didn't take me long to make up my mind that these liars warn't no kings nor dukes at all, but just low-down humbugs and frauds. But I never said nothing, never let on; kept it to myself; it's the best way; then you don't have no quarrels, and don't get into no trouble. If they wanted us to call them kings and dukes, I hadn't no objections, 'long as it would keep peace in the family; and it warn't no use to tell Jim, so I didn't tell him. If I never learnt nothing else out of pap, I learnt that the best way to get along with his kind of people is to let them have their own way.
Here we see Huck deciding that the best way to deal with people such as the Duke and the King is to keep quiet and not to challenge them. This continues to be his policy whilst he sees that the victims of the scams the Duke and the King create deserve their fate because of their own gullibility or their own unscrupulous nature. However, it is when the Duke and the King assume the identity of the Wilks brothers and Huck gets to know Mary Jane and her sisters that he decides he cannot sit back and watch the Duke and the King trick them:
I says to myself, this is another one that I'm letting him rob her of her money. And when she got through they all jest laid theirselves out to make me feel at home and know I was amongst friends. I felt so ornery and low down and mean that I says to myself, my mind's made up; I'll hive that money for them or bust.
The goodness of Mary Jane is the catalyst that forces Huck to stand up for what he believes in and thwart the scam of the Duke and the King. Note he still doesn't challenge them openly, but he at least acts to prevent their success.
Thus what is interesting is how Huck changes in his approach to the Duke and the King. He is quick to see them for who they are, but we see that it is only as his character develops that he decides to oppose their scams and stand up for what Huck is learning is right.