Answer:
this phrase is usually said when the person feeling is hurt. like the person need to learn the lesson so he/she doesn't end up in same situation again.
and this line "you taught me a lesson that I have to learn" it is also in the song "suícîdal" by YNW melly, the line gose like "You taught a lesson to me that I had to learn".