Somebody or some set of circumstances intervened very early on to get Ramos to barricade himself in that one classroom instead of roaming the building, killing people at random all through the school.
I know I said I was out, but a theory:
1. School admin initiated the lockdown internally in response to reports of Grandmother's shooting/ vehicle crash/ shots fired at nearby funeral home.
2. Most teachers complied and had locked their doors. 4th grade teacher failed, for whatever reason, to lock hers.
3. Backdoor was left unlocked, possibly due to parents coming and going from an awards ceremony earlier that morning. Ramos entered unchallenged.
4. Some combination of officers arrived just as Ramos was entering the school. Ramos tries to enter classrooms to escape them. There's a gun fight in the hall before Ramos enters the 4th grade classroom with the unlocked door.
5. At that point most of the massacre occurs. Ramos then barricades himself and the transformation from "active shooter" to "hostage taker" is complete.
6. The failure to secure the backdoor was the first critical failure. That's on the school personnel if there wasn't an SRO on property at the moment the attack started. If that door was locked, Ramos would have still been outside when officers arrived and more easily killed or captured with less danger to students.
7. The failure to lock the classroom door was the second critical failure. That's on the teacher. If that door was locked, Ramos would have been trapped in the halls and more easily killed or captured by responding officers following commonly accepted active shooter response.