appalling OP. absolutely appalling.
Leave your DS at home for a few days (is this an option?) whilst you gather some facts from the class teacher, speak to your GP to obtain a letter of support and then meet with the head.
Of course put your complaint in writing and take your mum or DH to the school with you, both on the fact finding mission and for the meeting with the head. You should expect a verbal and written apology to you and directly to your son, both from the teacher and the head.
Once you are reassured that this will never happen again then you can properly reassure your son about going back to class. Plus time will have helped him get over it. Of course, how the school deal with the complaint and how they discuss it with your DS, how they apologise and how they articulate to him "the plan to prevent this happening again" should also enable him to understand it wont happen again. They should be engaging him, not just you, but with you present.
Poor boy must have been mortified.
For him to develop sores suggests he was in that mess for at least an hour and it could easily have been 5 hours. How did anyone miss it?! Its beyond me.
You must advocate for your son and talk him through how to deal with the situation next time - ie ask once, then go if you need to go whether the teacher has said no or wait. He needs to know you will stand by him should the teacher try to punish him.
I would also send him in with spare clothes and wet wipes in his school bag (a small packet of the wipes so they are not too obvious to his mates, he doesnt want to be victimised - kids can be horridly intolerant to difference).
As for water: All kids should have a water bottle in class, which they should be encouraged to fill up at each break, so drinking water during class should not be an issue. There are plenty of studies showing that a small dip in hydration levels affects performance - both in sport AND in schools. Every school should therefore be encouraging re-fillable water bottles. I would not be happy with DS going to a school that did not do this tbh.
As for going to the toilet - if every class teacher allowed every kid to go to the toilet when they needed to then it would not be a novelty and 1 kid asking to go would not cause a tidal wave of kids wanting to go. It is ridiculous kids cannot go when they need to. Of course older kids should be expected to wait, if they can, but young kids should go when they ask to go - they are still learning fgs.
This irritates me so much. My DB is a Paediatrician and he sees so many patients who end up holding on at school, for a variety of reasons, causing themselves long term issues which he helps them to sort out but the solution is not always very pleasant and always takes at least 6 months.
Any school that told me my 5yo would not be able to go to the toilet when he wanted to would have a complaint filed with them, if that was not resolved I would then complain to the safe guarding officer and if that failed I would change schools.
Tbh given what you have said OP - are you prepared to change schools if the school do not react as one should expect them to? They do not sound particularly responsive to a 5yo's needs, let alone one with an issue that needs bearing in mind.