It is understandable that the length of a solar year can be found out using the time of solstices. But how did they find the length of a year with respect to the stars?
By looking at stars position with respect to the point of intersection of the ecliptic and equator (this is a position of the Sun at the equinox). Or which is the same at the position of this point among the stars. This position varies slowly (this is called precession of the equinox), and it was discovered by Hipparchus. Hipparchus work did not survive and it is known from Ptolemy. Since the precession is rather slow, about 1.4 degree per century, to detect it one has to compare two observations at the great time difference (several centuries). Since the time of Hipparchus this was done by many astronomers arriving to more and more precise values of the sidereal year.
Of course the practical problem is that Sun and stars are not visible simultaneously. But fortunately for astronomers: a) we have Moon, and b) Sun and Moon move approximatelty on the same circle. This permits to measure the angular distance between the Sun and Moon when they are both visible and then from the Moon to a star when they are both visible. For this reason, Ptolemy has to consider the motion of the Sun first, then the motion of the Moon and only after that he explains how stars positions with respect to the equinox point are measured. There is a continuing discussion lasting more than 100 years on the question "who made the first star catalog, Hipparchus or Ptolemy?" But Ptolemy's work is the only surviving ancient work where all this is explained in detail.