Moreover, why not 364 that would be 13 lunar cycles (28 days) or 52 quarter lunar cycles (7 days/1 week)?
They did it the same way you can do it today. First, look into the sky and find the "dog star," aka Sirius. Next, continue following that star until you arrive at a day that it becomes visible for the first time through the rising sun. This is known as a heliacal rising. Because Sirius is the brightest star, it follows that there will be a day when Sirius and only Sirius is visible through the dawn's sunlight.
The sun has two visible motions from the Earth. The first is the daily motion, and it happens once every 24 hours moving east to west. The second motion its yearly motion, which occurs west to east. This means that every day, the sun will move from west to east by about the width of your thumb (~1 degree of arc) against the background of the fixed stars.
That means that there is one day and one day only where Sirius has a heliacal rising where it is the only visible star at dawn with the sun bisected by the horizon. You mark that as day 1.
Now, you count days until it happens again. If you do so, you will measure 365 days. You could also count the days between any winter or summer solstice, or the number of days between either equinox. The point is, it's very easy to count days from any number of horizon phenomena.
The reason that ancient peoples preferred a solar year and not a lunar year is because astronomy/astrology was used for practical, predictive purposes. The heliacal rising of Sirius in June, for example, marked the flooding of the Nile. If you use a lunar calendar, it is going to drift and it is for practical, seasonal purposes useless. Using a solar based calendar, they were able to accurately predict seasonal changes that were important for their survival.
As for "who" was doing the measuring that I mentioned above, it was the Babylonians who did all the heavy lifting. The Babylonians expended great effort to compile detailed observations of all variety of astronomical phenomena (star risings, eclipses, zodiacal relationships) because they were believed to have predictive value that was highly valued by kings and rulers.
The full answer, however, is that they used both. In fact, great effort was put into reconciling the two calendars so both could be used. The first evidence of the Babylonians doing so was the as Mul.Apin in 1000 BC.
A good introduction to this subject (and one that goes over the Mul.Apin) is Chapter 1 of Tamsyn Barton's Ancient Astrology, published by Routledge, 1994.