Yes, P.E. or sports could always be at the end of the school day. Kids don’t need to be showering in open showers or changing in open rooms with other people.
Even the public gym I was a member of years ago had curtains on the individual stalls.
Why are children and teens being put on display in front of each other anyways? Not everyone practices custody of the eyes, some were never taught they need to. And even then it could be an occasion of sin for some, by curiosity, or worse.
I'm pretty sure they had to rotate the PE classes among different groups of students, hence the need to assign some students to PE 1st period, then another group 2nd period, and so on. In my experience, communal showering was never questioned, it was just "the way things were". It might be partially a cultural holdover from that time after WWII when there was a military draft, and they certainly don't make provisions for privacy in the military. At my middle school, built IIRC in the 1910s, they only had minimal partitions for the toilets in the restroom (they were so low that you could see who was sitting there, but "the business" was concealed on either side, with no doors). In the locker room, it was just military-style, no partitions at all. You did your business out in the open. Again, "just the way things were", nobody ever questioned it.
It might be different for females. Once, on a student retreat at a mountain camp (co-ed retreat), the girls were reluctant to take showers, and I asked a friend why. She told me that several girls in the class were known to be lesbians. Well, no s*** Sherlock, and even 40+ years back, I could probably go down the list and tell you which ones they were --- given that information, it would have been pretty much a foregone conclusion.