That'll teach (one) ((not) to do something) phrase
Whether the word "not" is used or not, the meaning remains the same.
Used when something bad or unpleasant has just happened to someone as a result of their stupid actions
A: "I can't believe that I failed that class." B: "Good. That'll teach you not to lie around all day."
I heard that Don just got rejected from a job he really liked. That'll teach him to think highly of himself.
Used to indicate that what happend or will happen to one is completely deserved