The most likely reason the author includes the sentence "Sometimes, lessons must be learned the hard way" is:
D To show that students may not see value in the law until they are directly affected.
This reflects the idea that facing consequences, such as not being able to participate in extracurricular activities due to failing grades, could lead students to understand the importance of maintaining good academic performance.