Dear "It is illegal for a teacher to refuse to let you go to the bathroom.",
That would only be in a public school. If you go to a private school, being allowed to leave the class to go to the bathroom isn't a right, it's a privilege that can legally be restricted.
Sincerely, don't want anyone making a fool out of themselves.