Turn your cloaks / For fairy folks / Are in old oaks - Old English saying
I couldn't find a definitive explanation of why this legend happens. What I have ascertained is that it turns up absolutely everywhere, not just in Irish stories. I have found a few quotes that begin to offer a reason (although, I have to say, not a hugely satisfying one).
The main reason offered appears to be to confuse the fairies. These sort of beings are depicted as mischeivous, and to counter their mischief, one could do something unexpected, to confuse them. 992
This didn't necessarily repell them, in the same way that iron (which they were generally scared of) or other things might - it was more a last-minute distraction, designed to give you time to escape any enchantments, rather than a lasting effect.
It's largely associated with pixies, as well as spriggans - it is often offered as a solution to being pixie-led:
[Pixies] took a delight in misleading night-bound weary travellers until they became exhausted and lost; this was called being "pixy-led"... The usual manner of disenchanting oneself from this situation was to remove one's jacket and put it back on inside out.
Spirits, Fairies, Leprechauns and Goblins, <PERSON>
Humans become lost on the trackless moors of Dartmoor are said to have been "pixie led", or led astray by the pixies. It is said that if travelers feel the onset of the pixie spell, they can turn their coats inside out to confuse the pixies and escape.
An Encyclopedia of Mythology and Folklore, <PERSON> (emphasis mine)
One way of avoiding fairies and their magic was to wear one's clothing inside out, which would confound them. Fairies were also reputed to be terrified of iron or steel, so even a single pin could prove effective against them.
The Everything Celtic Wisdom Book, <PERSON> (emphasis mine)
This source also offers another alternative:
Actions could break the fairy spell. The most common one was turning one's clothing inside out or wearing it backward, the latter presumably based on the idea that the fairies fail to torment someone who seems to be departing rather than approaching.
The Encyclopedia of Celtic Mythology and Folkore, Patrician Monaghan (emphasis mine)
Finally, not an official source by any means, but this blog post offered an explanation which seems plausible and takes the idea of confusing the fairies a step further (and which I quite like - emphasis mine):
The presciption, intended to break the binding spell of the fairy otherworld, is a fight fire with fire recommendation; turning your coat inside out corresponds to and counters the inherently contrary nature of Elfland (It is Summer there when it's Winter here; we grow old, they grow young, etc.) ~ thus by doing something irrational within irrationality, one may flip the coin and come out back in the comfortably predictable and thus, safe, world of the mundane. 712