While Tom Sawyer does get into trouble with the schoolmaster, Mr. Dobbins, throughout the book, their interactions don't culminate in a revenge plot during graduation. The most notable interaction between them involves Tom getting caught cheating in school and being punished with a thrashing.
It's possible you're thinking of a different story or movie adaptation. Could you provide more context or details about what you're remembering?