I've reread the original post and missed the point (about the triggering episode occuring initially by the older child, in the washroom, when your daughter was 3). Undoubtedly this is where she picked up the example behaviour (older kids undressing younger kids). Now she's 5 so she sees this as expected behaviour (it apparently was a memorable enough episode that it's etched firmly in her memory). A behaviour that was experienced, might out trump a parents continuing instruction(s) to the contrary.
Knowing this, teachers sometimes resolve the problem by assigning a (safe) buddy to accompany children who've demonstrated this behaviour to the washroom rather then letting them get into mischief on their own and unsupervised. A classmate of your daughter's age and not easily coerced ought to be safe from her behaviour. She ought not have any further opportunities to encounter much younger children in washrooms without anyone else present.
Hi there. I see a great issue with children disappearing into the bathroom for long periods of time. That needs investigation immediately. Especially if they are in different classes and are different ages. Schools generally keep tabs on the students, it's their job.
Do you not think what happened when she was young had something to do with this? I would guess yes. And wonder if other things like this happened.
I would not freak out. I would ask her why and how she came up with the idea calmly.
When odd and persistent sexually oriented behaviour suddenly occurs in very young children, I think it's prudent to look around and make inquiries (about the possibility of inappropriate contact by an older person having occurred earlier). Perhaps their behaviour can be a form of acting out not quite randomly in response to an earlier episode (perhaps of similar behaviour they experienced), and is their way of dealing with what to them is imponderable.
The problem with obtaining professional help in such matters is that young children are apt to say whatever they think the stranger wants them to say. (the children are extremely open to suggestion whenever leading or suggestive questions are used, an inexperienced interviewer or an experienced one with a predisposition away from careful fact finding can cause great harm to an investigation that way).
If there were to be any interviews of your child of this character, I urge that they be recorded (preferrably video recorded and showing the interviewer's facial expressions). [I'm not a parent.]