My son had issues with non-home bathrooms. He wouldn't have accidents so much as unhealthily hold it in. That was the main reason we opted for half-day SPED instead of regular full-day pre-k, at first.
If he has no general issue with this, it could be that the bathroom he is expected to use is the problem ---too loud, too gross, too something. The sink's water could be too spurty or too loud, too.
Alternately, he could have issues with not wanting to miss out on "fun" while he is gone, or just feel weird leaving.
A different, quieter bathroom might help, a single private room like the nurse's might help, or maybe a social story on why he has to go when he has to go.
Dinosaur Train had an episode on this as did Daniel Tiger. I can't think of the episode names, off-hand.