This sentence is a typical example of the second conditional, used for hypothetical or unreal situations.
\[\begin{array}{rl} \bullet & \text{(A) "If I were him": In formal and correct English, the subjunctive mood "were" is used after "if" for all persons (I, you, he, she) in hypothetical clauses. This part is grammatically correct.} \\ \bullet & \text{(B) "I would teach": The main clause in a second conditional sentence uses "would + base form of the verb." This part is also grammatically correct.} \\ \bullet & \text{(C) "him a lesson": This is the object of the verb and is grammatically correct.} \\ \end{array}\]
Since all parts of the sentence are grammatically correct and form a proper second conditional sentence, there is no error.