Here's one way of looking at it: Injun Joe murders Dr. Robinson and frames Muff Potter; Tom comforts Muff Potter and eventually takes the stand to clear his name. Tom's clearly the better guy, right? Well, yes, but it's not so easy. Tom also derives pleasure from letting people think he has drowned. He steals sugar and beats people up. In short, Tom does some bad things, but he compensates for them by doing very good things.
Take a look at this line from the end of Chapter 17:
First one and then another pair of eyes followed the minister's, and then almost with one impulse the congregation rose and stared while the three dead boys came marching up the aisle, Tom in the lead, Joe next, and Huck, a ruin of drooping rags, sneaking sheepishly in the rear! (17.12)
Twain tells us all we need to know just by describing Huck's attire. It's no surprise that no one in the crowd pays attention to him until Tom points out how pitiful he looks.
Tom and Huck both come from what might be called "non-traditional" families. Tom lives with his Aunt Polly, his weaselly stool-pigeon of a brother Sid, and his saintly cousin Mary. Huck has no mother and a drunk for a father. Though Twain does manage to hook Huck up with a mother figure of sorts, the Widow Douglas, by book's end, his depiction of family life doesn't seem to function as any kind of social commentary. It's just what you might call a choice on the author's part. It certainly does give Huck a lot more freedom, though, and, as Huck himself discovers, a Huck without freedom is scarcely anything at all.
You've heard people talk about the haves and the have-nots, right? Well, in Tom Sawyer, it's about the dos and do-nots. The respectable characters in Tom Sawyer – people like Judge Thatcher and Aunt Polly and the Widow Douglas – do something. The Judge judges, Aunt Polly takes care of her children, etc. The bad guys, on the other hand, don't really have jobs. Injun Joe isn't a lawyer by day and murderer by night. He's just all around bad. His accomplice, the one who ends up dead in the river, doesn't do anything at all as far anyone knows. And Muff Potter? Well, he ends up in a bad place because he doesn't have anything to do but drink.