Under the old Ptolemaic system of astronomy, the earth is at the center of the universe, and the sun and planets revolve around it in circular orbits — but the planets obviously don’t revolve around the earth in perfect circular orbits, because they occasionally seem to move in the wrong direction. This retrograde motion was explained via epicycles — the planets supposedly moved along a small circle that itself moved in a circular orbit around the earth.
As early astronomers made more and more observations, they needed more and more epicycles on epicycles to explain the planets’ paths:
In part due to sometimes fantastic attempts to make the failed earth-centered model work, “adding epicycles” has come to be used as a derogatory comment in modern scientific discussion. If one continues to try to adjust a theory to make its predictions match the facts, when it has become clear that the basic premise itself should be questioned, one is said to be “adding epicycles”.