Our Gemara discusses the timing of Sukkot and comments that the first day cannot fall out on a Friday. If the new moon of the month of Tishrei appears on a Friday, which would cause the 15th of the month (the first day of Sukkot) to fall out on Friday, as well, we push off the first day of the month – Rosh HaShana – to Shabbat. The Gemara explains that this reconfiguration of the lunar calendar is necessary because we want to avoid having Yom Kippur, which is on the tenth day of Tishrei, fall out on a Sunday.
The discussion in the Gemara is based on the contemporary lunar calendar which is a set calendar and is not based on testimony from witnesses who come to the Sanhedrin to report on their seeing the new moon. According to our calendar, Rosh HaShana can never fall out on Sunday, Wednesday, or Friday, so Sukkot, which is exactly two weeks later on the 15th of the month, cannot fall on those days either. This arrangement is made in order to avoid having Yom Kippur fall on either Friday or Sunday, since two days in a row (including Shabbat) on which all work – even cooking – is forbidden, would be difficult for people.
According to some sources, it appears that even when the calendar was based on witnesses who came to testify that they saw the new moon, various methods were employed to insure that Yom Kippur would not fall out immediately before or after Shabbat. Nevertheless, it is likely that, on occasion, it would be impossible to shift the day, since a month cannot be less than 29 days long (according to our present-day calendar, Rosh HaShana is sometimes pushed off from the actual new moon by two full days to accommodate the needs of these holidays) and Yom Kippur would fall out on Friday or Sunday.
According to the Rambam, the shift in the calendar serves another purpose, as well. He believes that pushing off Rosh HaShana allows for a more precise correlation between the solar calendar and the lunar months, correcting minor discrepancies that exist even when the leap year is added at the correct time.