Why did people in Ireland believe there was gold at the end of rainbows?

They didn't. It was all a big misunderstanding.

Rainbows are formed when light hits droplets of rain. Each droplet acts like a prism, splitting the light into different colors, each of which is bent at a slightly different angle. That's what forms a rainbow. Because the light source, the sun, is a circle, and because light travels in a straight line, the rainbow is a circle as well.

In order for the sun's rays to refract so we can see them, the sun has to be within 42 degrees of the horizon either rising or setting. That's pretty low, which means we can never see the full circle of a rainbow - we just see the top part of the arc.

As far back as the 17th century, the Irish understood this. And they were fond of saying that one was as likely to find a pot of gold as to find the end of a rainbow. The expression somehow changed and became a part of fairy mythology.