For what reasons is a class expunged instead of dropped?
It depends on the institution. I had a class dropped as an undergraduate (my advisor told me that if I registered as extracurricular, I wouldn't have to take the final exam, I would just get a pass/fail based on my homeworks. I found out he was wrong about that 2 weeks before the final when they sent out the exam schedule and I was registered for the final exam in that class (turns out the changed the rules for extracurricular classes the year before). Fortunately, I had the conversation with my advisor over email, so it was declared clerical error and the class was expunged from my record. Another student in my class was hit by a car a few days after the last day to drop classes and hurt badly enough that he needed a semester off. All of the classes he was registered for were expunged from his record, and his transcript reads that semester as free for health reasons.

Most universities will expunge a class from your records if you have a good reason: typically clerical error or health (including mental health) reasons. Some universities will instead let you "withdraw without penalty" if it is for health reasons. The only way to know how your university does it is to check the regulations or ask your advisor.