Historically, when discussing the issue of chazal and science, most rishonim and acharonim have been of the opinion that chazal used the contemporary science available to them, but had no special knowledge of the 'secrets of the torah' which gave them superior knowledge than the Greeks or contemporary science. This was the opinion of Rav Shrira Gaon, Shmuel Hanaggid, The Rambam, R' Avrohom ben Harambam, Ibn Ezra, the Radak, the Ralbag and others. This site has a very nice collection of sources to that effect.
However, more recently, the has arisen a movement which claims that such a thing is heresy, or at least blasphemous, and they have their roots in sefarim such as be'er hagolah from the Maharal, a statement from the Rama in Toras Haolah, among others. Some have even found sources which predate them, see here for example. This view has some basis in various writings of the Vilna Gaon, and was endorsed by many recent Gedolim such as the Chazon Ish, R’ Moshe Feinstein, R’ Elyashiv and others. Rabbi JB Soloveitchik famously asserted that טב למיתב טן דו is a fundemental reality which can never change, and Rabbi Meiselman in his book Torah Chazal and Science quotes him as saying that anyone who claims chazal made in error in anything is a heretic as he falls into the category of מכחיש מגידיה. (This idea was [in]famously used by the zealots [such as R’ Aharon Feldman, R’ Elya Ber Wachtfogel, R’ Uren Reich] during the Slifkin affair.)
(It has become a popular yeshivish adage התורה קובעת המציאות ולא המציאות קובעת התורה, and this is taken to mean that being that the torah is the source of reality as inאיסתכל באורייתא וברא עלמא, if the idea is contained in the torah including torah sh’baal peh, than the metzius will necessarily conform to that, rendering chazal inerrant.)1
Nevertheless, within halachic literature the attitude has always been that chazal's rulings even when they are based on scientific positions are always correct, and there has never been much of an issue raised in cases when they don't seem to align. For instance, the famous tshuva of the Rashba about treifos and the famous tshuva of the Tosfos Yom Tov regarding fish with scales but no fins are unyielding in their affirmation that chazal were necessarily correct. We also never find much of a movement to update halachos which are based on faulty science, from shkiya of rabbeinu tam, to bliyos, to the sakana of fish and meat or leaving nails around, to numerous אומדנות throughout halachic literature, to the scientific underpinnings of much of hilchos niddah, hilchos treifah, and much more2.
Why the discrepancy? From a sociological perspective it seems very understandable. Ever since the Talmud has been accepted as the final opinion in halacha the body of halacha has focused very strongly on halachic statements of the talmud, and never reevaluated anything since. Even statements which are not necessarily halacha, such as the danger of leaving nails on the ground (which was a known Zoroastrian belief in Persia during the talmudic era), since it has crept in to sources such as Shulchan Aruch, it has never merited it's own reevaluation (unlike many other non halachic instructions such as the refuos in the gemara, the various instuctions about drinking water in shabbos, or other such gemaros [althoוgh some statements have still survived on theןr own such as zugos until several hundred years ago and others]).3
However, this doesn't actually offer a justification how two conflicting positions can be held. Were they correct in their science or were they not? For many today, this provides a strong basis to their belief that chazal can never be mistaken, even in non-halachic matters. If you don't accept this, why trust them in halacha?
Rav Dessler offers a novel solution, but it's very difficult to accept. He claims that even when they gave theןr reasoning based on theןr scientific understanding, there are many reasons, and they knew the halacha b'mesorah, so although they may have been mistaken in the science, the halacha remains the same.
I've seen another solution given based on the rambam by hilchos treifah, where he says that even if the doctors say the animal can live, it is still a treifah because of על פי התורה אשר יורוך. However, this does not seem to be a comparison, as treifah is a halachic category defined by chazal, and is not directly dependent on the science, so although they may have done it based on faulty reasoning, the category remains in place, unlike say killing lice on shabbos, which is simply a question of reality and if they're wrong the halacha should change. (One might argue that as long as we do not have access to better science you can rely on their psak, but if we know they were wrong that seems highly implausible.)
One approach many modern thinkers like to advocate is that halacha is a legal system, and if the authoritative texts in the tradition mantain such a position, unless a move is made specifically to change it, the status quo remains, and regarding halacha we consider that to be the reality, similiar to a legal fiction.
However, this assumes that the ontological nature of halacha is that of a mere legal system. If we were to assume that the current form of torah sh'baal peh was developed during the rabbinic period and not a direct tradition going back to Sinai, this assumption would be justified. However, the traditional position in classical sources is that it is not a sociological construct, rather a very real intepretation of the torah which was given directly to moshe at sinai, either as a whole (the position of the sifra, ran, ritva, rashi and others) or at least the method (rambam). In such a system, halacha would seem to be an innate metaphysical property of the world, as it defines the absolute will of god and therefore can be described as a complete ontological description of reality. This approach is explicitly adovocated in kabbalistic sources (and in the contemporary brisker approach to lomdus).
Are these two positions mutually exclusive? Can one be a halachic realist while allowing for scientific errors in the halachic process?
I submit that they are indeed a contradiction. Halacha must submit to scientific reality, and the fact that it doesn’t indicates that it claims to be infallible. How can we reconcile this with all the rishonim and acharonim who thought otherwise? Simple. Halacha never became self aware of its own limitations. The halachists throughout history never reevaluated halacha in light of updated science, as they were largely unaware of science and simply trusted the talmudic sources they were apt to rely on. When issues crept up, some mantained the claim the chazal were inerrant, while those more engaged in other pursuits, such as the Rambam and other Spanish scholars, simply mantained a cognitive dissonance and never resolved the issue. They may have chose not to change halacha for fear of threatening the system as a whole, 4 but this could not have been a conscious process, as this would violate the inherent obligation to ensure that the halacha was codified properly and free from scientific error. As we entered the Enlightenment and confronted these issues en masse, we began to develop theologies either to the effect that chazal were inerrant or that halacha is not restricted to the actual science.
Those that subscribe to kabbalah may have other considerations which support viewing chazal as inerrant, as kabbalah tends to consider every word of chazal as containing deep secrets of creation, as demonstrated by the Maharsha, Maharal, Ramchal, Vilna Gaon, and various Chassidic masters. However, it is an objective fact that this has not been the historical view, and in modern times Rabbi Shamshon Raphael Hirsh and Rav Kook, who were both deep believers in kabbalah, have each written explicitly against the idea of inerrancy.
I have not had the time to elaborate on the scientific errors in halacha, and maybe one day I will compile a comprehensive list, but I am certain that there are hundreds if not thousands of scientific errors codified in Shulchan Aruch, most of which have their roots in ancient scientific theories.
Interestingly, regarding a baby born in the 8th month, on whom the Talmud and Shulkhan both rule הרי הוא כאבן ואסור לטלטלו ואין מחללין עליו את השבת דכמת הוא, as the Greeks believed he was deformed and incapable of survival, all modern poskim agree that ‘נשתנה הטבע’ as we see that they survive nowadays. (See חזון איש יורה דעה, סימן קנה ס"ק ד among man others.) However, the impetus to do this was clearly that there is a life of a baby at stake, and we must ‘change’ halacha (similar to what was always done in high stakes situations such as relationships with gentiles in Christian Europe or attitudes towards modern secular jews).
If this is true it might explain why in the period of the rama in particular we often find the concept ובזמנינו אין נוהגין כן, and many halachos were changed or adapted. This was the height of stability for the halachic process, compared during the rishonim when halacha was still coalescing and the Karaites were a powerful force, and the modern era when the reformers were threatening halacha altogether), so they felt comfortable making changes.
Great, nuanced piece
Many years ago, there was ablogger that described the biggest problem with Halacha is our inability to update it based on reality. He described it as a building where we keep adding layers when lower ones make issues instead of going back down to the foundation and reconstructing it.
Anyone who has a scientific mind has already pondered this issue, that halacha is unfalsifiable and unfixable due to the fact that we cannot argue with chazal based on facts.
My answer is this: While I would not agree that halacha is sociological rather than metaphysical, God did not want us to update it independently due to sociological issues. There are many people who tried to update halacha (probably the most recent is David Bar Hayyim of Machon Shilo) but it never catches on and the result is there are two torot in Israel. Rather, Hashem wants there to be an authoritative group responsible for updating that will be accepted by all of Israel. In my opinion, should the Sanhedrin be reinstated, the very first thing they would do is update hilchot kashrut and niddah and so on. It is only due to the tremendous machloket and lack of legislative power we are unable to do so today, and we should not even try.