Concept:
When two separate actions occurred sequentially in the past, the past perfect tense (had + past participle) must be used to express the action that completed first, while the simple past tense handles the action that occurred later.
Step 1: Establishing the sequence of events in the past.
The sentence establishes two actions: the teacher entering the room (entered - Simple Past) and the students completing their writing. Because the students completed their work before the teacher entered, the earlier action must use the past perfect form: had finished.