As a novel that conveys a moral lesson—with characters who symbolize different parts of American society—The Adventures of Tom Sawyer could be considered an allegory. Twain grew up in the mid-19th century in small-town Missouri, where morality was tied to Christianity but also full of contradictions—people claimed to be committed to a certain faith or denomination but then got swept up in the new religious revival of the day, others publicly supported the temperance movement but would drink alcohol in secret, etc.
In writing Tom Sawyer, Twain sought to spin a symbolic tale centered on a hero fighting against the hypocrisy of society and ultimately finding a way to become moral on his own terms. In this way, Tom symbolizes the moral American who questions punitive Christian society (as represented by Aunt Polly and many other villagers in the town). In his questioning, Tom finds he can wield power over his more simpleton friends (who represent average people looking for a leader) but is not seduced by that. For example, he manipulates all of the boys in the village into whitewashing Aunt Polly's fence but never pulls another stunt like this. In fact, Tom moves on to spending time with Huck Finn, who symbolizes the complete rejection of society.
After experiencing this kind of social rejection (as happens during their time on the island), Tom realizes that he misses the comforts of community, and the rest of the novel is centered on him facing different challenges as he tries to remain part of society while also developing a morality all his own. His feud with Injun Joe could be seen as Tom fighting the part of himself who could easily become Injun Joe, given his desire for adventure and excitement. In the end, Tom is rewarded (financially and socially) for performing moral deeds, like testifying against Injun Joe in trial and taking care of Becky when they're trapped inside the cave. The treasure that he finds is symbolic of the riches that come from seeking morality while also maintaining a healthy degree of skepticism and individuality.