The Jerusalem Talmud, Horayot 1,1 explains:
“You would think that if they [the rabbis] said to you concerning
right that it is left and concerning left that it is right you should
obey them, therefore the Torah tells you to go right and left: if they
tell you concerning right that it is right and concerning left that it
is left [then you obey them, but not if they tell you that right is
In paraphrasing the Talmud, Rashi writes, based on Deuteronomy 17:11 and Midrash Sifrei, that:
“even if he [the rabbi] tells you regarding the right [hand] that it
is left, or regarding the left that it is right, and certainly so [you
must obey the rabbi] if he tells you regarding the right [that it is]
right, and regarding the left [that it is] left.”
Yisachar Eilenberg, wrote that Rashi only meant his writings to refer to someone who heard a rabbinical verdict but is unsure whether the rabbi is correct. Whereas the Talmud refers to a case where the rabbi is wrong and the person should not obey the verdict.
For example, when the Patriarch Rabban Gamaliel and sage Rabbi Joshua ben Hananiah calculated the date of Yom Kippur differently, Rabban Gamaliel ordered Rabbi Joshua to appear on his version of Yom Kippur, in violation of the law, as according to Rabbi Joshua. “I command you to come to me with your staff and money on the day of Yom Kippur according to your calculation.” When Rabbi Akiva quoted Leviticus 23:4, Rabbi Joshua obeyed him based on Deuteronomy 17. The moral of the story is that you can disagree with the rabbis privately. Rabbi Joshua was convinced that he was correct. But that you must obey the rabbis publicly, as to avoid division in Judaism and to keep the peace. The Talmud relates:
He took his staff and money in his hand and went to Yavneh to Rabban
Gamaliel on the day he [Rabban Gamliel] had calculated to be the Day
of Atonement. Rabban Gamaliel stood up and kissed him on his head and
said to him: “Come in peace, my rabbi and my pupil; my rabbi in
wisdom, and my pupil, because you accepted my words.”
According to Rabbi Angel, the Sanhedrin “even had the power to overrule a law of the Torah (see, for example, the discussion in the Talmud, Yevamot 90b.” And that it “ruled according to the way it seemed to them that the law should be – their judgment is the law. If a subsequent Great Court found a reason to refute their decision, it should refute it” for the Torah says to “only obligated to follow the Court which is in your generation.” Maimonides writes that ancient law was flexible (Mishneh Torah, Laws of Rebels 2:1). But writes in Hilchot Mamrim 1:2, to accept rabbinical mandates. In Mishneh Torah, Rambam avoids the issue of “right and left” altogether. H writes in the Guide that, “A man should never cast his reason behind him, for the eyes are set in front, not in the back.”
Lastly, Avot 1:6 recommends "providing yourself with a teacher." "Make yourself into a great rabbi." R. Galanti posits that this means becoming a Torah scholar and a great tzaddik. Thus, one should be well-informed in order to make reasonable halakhah decisions. Hillel agreed. He said, "he who does not increase his knowledge decreases it (Pirke Avot 1:13)."
 Similarly, the Ran wrote:
“even if it is crystal clear to you that what the court [or rabbi]
tells you is wrong, nevertheless obey them, for this is how G-d, may
He be blessed, commanded that we should behave towards the Torah and
its commands: do as they decide for us, whether it is true or false.”
 Author of Tzedah laderech (seventeenth century).
 Jacob Makelberg, author of Hakhatav v’hakabala (nineteenth century), agreed.
 See Babylonian Talmud, Rosh Hashanah 25a, and Mishna Rosh Hashanah 2:9.
 See his book The Rhythms of Jewish Living.