Where did this model come from?

The main point is that this model (with slight refinements irrelevant to our argument) gives an excellent account of the movements of Mercury and Venus through the heavens, and was accepted for one thousand years. Remember that even in Galileo's time, (almost) everyone believed the Earth was the fixed center of the Universe, and the Sun circled around it.

Still, you might think, even if we grant that the Earth is fixed at the center, why not just have Mercury and Venus circling around the Sun, with the Sun itself circling the Earth? Wouldn't that give an equally satisfactory account of their motion through the heavens? The answer is that it would, but that fits less well with the way the Greeks envisioned the heavens. They thought the planets were fixed to sets of concentric crystal spheres, centered on the Earth. The motion of a single planet required more than one such sphere: it needed two (or in some models more), like a three-dimensional version of the epicycles, a sphere rotating about an axis, the axis locked to another sphere whaic was itself rotating about another axis. Ptolemy's cycles and epicycles were just a convenient mathematical representation of the motion.

But if you allowed Mercury to circle the Sun, and ascribed some degree of reality to the concentric spheres picture, Mercury would break through the Sun's crystal sphere. To avoid suggesting that possibility, in Ptolemy's picture Mercury goes around a scaled-down version of what we know is its real orbit around the Sun, at a correspondingly scaled-down distance from Earth, to give the same motion across the heavens. So this picture follows the ancient tradition of the separate planets (and the Sun) having their own spherical shells to move in -- all centered, of course, on Earth.

Note that these two planets never get further than a fixed angular distance from the Sun, in contrast to all the other planets. Think about how that comes about with our present understanding of the orbits.

Contrast this with his model for the outer planets.