Question: what does mean in which?
Answer: It means the thing after “in which” is used happened in/during the thing before it. The sentence you gave means that during the punishment, the student has to stay at school after everyone left.