Nobody knows for certain what the origin of ‘loo' for ‘toilet' is, but here are a few possibilities...
a) There may be a connection between the name 'Waterloo' and the idea of a water-closet (WC).
b) Alternatively, it may come from the French word 'lieu' meaning 'place' and hence the idea of a special, private place for one's bodily functions.
c) Another possibility is that it may be based on the cry of "Gardyloo!" This was basically the cod-French, "Garde l'eau!" or "Beware of the water!" apparently used in 18th century Edinburgh. People there shouted that when they threw the contents of their chamber-pots out into the street!
d) Finally, it has even been suggested that it may be a corruption of ‘lee', meaning ‘the sheltered side', that being the direction in which one should - obviously! - urinate aboard a boat!
A detailed examination of all the possible origins of this word was published in Blackwood's Magazine in 1974. The writer, ASC Ross, favoured 'Waterloo', which is why I listed it first above, but could not definitively prove it. As a result, The Oxford English Dictionary, the 'bible' of word origins, says: "etymology obscure".
There are times when we just have to accept that there is no certain answer.
Certainly, the earliest recorded use of it was in James Joyce's Ulysses published in 1922. He, of course, was noted for a love of playing around with words, so maybe the whole thing is just an Irish joke!