It's a balancing act for teachers. If they just let everyone go to the loo, whenever they asked, it would cause a lot of disruption in the class - and your child's education would suffer as a result.
Obviously they don't want any child to become ill, or soil themselves, or become unhappy to be in school either - so they have to walk a fine line between letting them all go willy nilly, and never letting anyone go.
The most sensible approach, which I have seen outlined on several threads on this topic recently, is to ask the child to wait, and then see if they forget their need to go - and if they ask again, let them go.
It is also worth parents reminding their children to go to the loo at break time and lunch time, because this will reduce the likelihood of them needing to go 'desperately' as soon as they get back into class.
Like it or not, some children will ask to go to the loo because they want to get out of class, or because they want to go and create mischief in the loos. And if a school has a policy that no child is allowed to go to the loo outwith breaktime and lunch time, the teacher can get into trouble if they do let children go to the loo.
A child with a medical need should have a card they can show, so they can go to the loo when they need to, without a lot of palaver.