One of the legends of the fair is that the event pays tribute to a goat that broke away from its herd, while the rest of the herd headed towards the mountains, and warned the town's inhabitants while the “Roundheads” were pillaging the countryside around Shanara and Kilgobnet at the foot of the McGillycuddy Reeks. The advancing army of Oliver Cromwell during his conquest of Ireland in the 17th century triggered the pillages around the countryside. The goat's arrival alerted the inhabitants of danger, and they immediately set out to protect the town and their herds. This is explained in the traditional Irish ballad, An Poc ar Buile (the Mad Puck Goat).
Scholars speculate that the fair's origins stem from Pre-Christian Ireland, from the Celtic festival of Lughnasa which symbolised the beginning of the harvest season, and that the goat is a pagan fertility symbol.
Very cute animation
Here's a translation I found of the lyrics https://songsinirish.com/an-poc-ar-buile/