In the same way that learning a lesson in school is important, learning in life is important too. The meaning of the idiom to learn one's lesson is to make a mistake and learn something valuable from the error.
Example 1: I really learned my lesson when it came to driving too fast - I got too many tickets and almost lost my license.
Example 2: She will either learn her lesson when the supervisor finds out what she's been doing, or she'll lose her job.
Example 3: A person who has learned a lesson in life is very unlikely to repeat the same mistake, but it sometimes happens.
Example 4: After I almost drowned, I learned my lesson and started taking swimming classes.