They made star maps. They mapped the posiitons of stars on the imaginary celestial sphere - whch they thought was an actual physical hollow sphere surrounding the Earth at some distance.
Because the earth rotates, and they thought that the Earth stood still, they believed that the imaginary celestial sphere rotated around the Earth. They saw that stars near what we call the north celestial pole rotated around that pole in small circles, travelling 180 degrees per night. And they noted that amoung the polar stars A Star A might be above Star B at midnight on midsummer, and be below star B at mightnight in midwinter.
And they knew that at midnight the Sun was on the opposite side of the Earth from the stars which were on a line from due north on the horizon to the zeneth. Once water clocks or hourglasses were invented, they could tell how many hours of darkness there were each night of the year. And it would be midnight right in the middle of the period of darkness.
When they had all of the northern half of he celstial sphere and much of the southern half mapped, they could figure out which stars were opposite to the midnight stars each day of the year, and thus know "where" the Sun was at noon any day of the year.
They could measure how high above the horizon the Sun was at noon every day of the year, and figure out how that related to the equator of the celestial sphere. Thus they knew the latitude of the Sun above or below the equator of the celestial sphere every day.
So they knew the longitude of the celestial sphere that the Sun was in because it was opposite to the longitude of the sars which were due north at midnight that day.
And they knew the latitude of the sun relative to the celestial sphere because they could mesure the Sun's angle aobve the horizon at noon during the day and convert that to the Sun's latitude on the celestial sphere.
Thus they could map the position of the Sun in the celestial sphere each day, with greater and greater accuracy as the decades and centuries passed.