Edit: The wiki also says it's possible for NPCs to randomly walk in from the connecting hallway, and all of that info was presumably written before modules were a thing. While a lot of the info in the wiki might be wrong and/or outdated, it does seem to confirm what I've seen:
You must be registered to see the links
Okay, this adds a lot of significance
This hallway connects to the staff (teacher) room, which contains the book used to change clubs when interacted with. Teachers frequently appear in the staff room, and the AI in this game seems to come from a set of rules that work much like a large module, for example the AI replacement mod I linked earlier. So the game's rules sometimes pushes teachers to the staff room, and thus through the hallway on the way to the room. Students may target the teacher to follow them into this hall or the staff room, then usual AI poking pushes them into the hallway from the staff room or they managed to reach the teacher before they entered the staff room
From there, occupants of the staff room enter the hallway. From there, occupants of the hallway enter the infirmary.
So it's rare, but within usual rules for people to wind up in the infirmary sometimes. It just depends on the teacher's destination habits and what students tend to follow the teacher most often. Events like fights and sex makes students run away to adjacent rooms, forcing wandering to happen.