One of the most important lessons that Huck learns is that adults are not always right in their thinking and decisions. He has always been submissive towards adult authority, although he is contemptuous of it, and he assumes that even obvious con-men and dullards like the Duke and Dauphin have some knowledge of the world that he lacks. However, events show him over and over that everyone is fallible, especially when it comes to the treatment of slaves. While Huck never fully embraces abolitionism and racial equality, he comes to realize that his friendship with Jim is deeper and more honest than most of his other relationships, simply because neither Jim nor Huck are trying to take advantage of the other.
After all this long journey, and after all we'd done for them scoundrels, here it was all come to nothing, everything all busted up and ruined, because they could have the heart to serve Jim such a trick as that, and make him a slave again all his life, and amongst strangers, too, for forty dirty dollars.
(Twain, The Adventures of Huckleberry Finn, gutenberg.org)
The incident where the Dauphin gives Jim up shows Huck that he can't really trust most people; everyone is out for themselves, and he must be more clever than most to escape trickery. He also realizes, after some mental struggling, that he would rather be a criminal and steal Jim back than allow his friend to be returned to a life of slavery. Jim -- and by extension other slaves -- are people just like anyone else.
My new novel, Huckleberry Finn Grows Up, which will be published in a week or two, deals precisely with this issue. One thing Huck learns is that black people are human and have the same feelings (for insstance, love of family) as white people do. Another thing he learns is that his vision of the right thing to do (help Jim escape) is different from the vision of the society around him (turn Jim in); he learns to trust himself and his own view of right and wrong.