Huck has been brought up to believe that certain actions are moral and true while others are not. His culture believed (mostly) that slaves were inferior and that they should be kept instead of allowed to be free. Huck thinks that as long as Jim is going to be a slave, he should at least be with his own family, and determines to write a letter to Miss Watson, betraying Jim. However, in thinking about Jim, Huck realizes that their friendship on the river was real and more important to him than the cultural relativism of morality:
It was a close place. I took it up, and held it in my hand. I was a-trembling, because I'd got to decide, forever, betwixt two things, and I knowed it. I studied a minute, sort of holding my breath, and then says to myself:
"All right, then, I'll GO to hell" -- and tore it up.
It was awful thoughts and awful words, but they was said. And I let them stay said; and never thought no more about reforming.
(Twain,The Adventures of Huckleberry Finn, gutenberg.org)
When Huck says, "I'll go to hell," he means that he is determined to take the consequences of his actions, regardless of their severity, if it means doing what he determines is right. He believes that his decision to steal Jim is better and more moral than to give him up or leave him in slavery, and if society and religion make him out to be evil, so be it. Huck is willing to risk the damnation of his soul -- as he understands it -- to be true to his friend.