It is generally frowned upon, because it's a formal military occasion.
HOWEVER... depending who is overseeing the whole event, he / she will say in their initial welcomes that civilian guests or pregnant may leave the table. Couple with the fact that the Officer / SNCO that has invited siad guest is normally then haranged into buying a bottle of port etc anyway!
But to be honest, if you visit the toilets during the breaks that are factored in you will be fine.
As has been said already there will usually be breaks factored in when you can leave the table. Even 'stag' (serving members only) functions include some form of comfort break. Don't fill yourself up with drink before you go to the table and decide whether it is worth 'breaking the seal' at the 5 minute call before dinner.
As for why it is bad etiquette it is simply a tradition. Over time this has been (sensibly) eroded to allow functions to become more enjoyable rather than some form of torture. The comfort breaks factored in allow the formality of the occasion to remain without people getting up and doing their own thing like some sort of pikey wedding.