The Torah tells us that we must obey the Sanhedrin in the well known verse in Devarim (17:11) According to the Torah which I will teach you and the laws which they will tell you, don't turn from that which they say right or left. Rashi(Devarim 17:11) comments that this requirement to obey them is, Even if they tell you that "right" is "left" and "left" is "right" and surely if they tell you that "right" is "right" and "left" is "left". The Sifre (Devarim 154:11) modifies this a bit, Right and left - Even if it appears in your eyes that "right" is "left" and that "left" is "right" – you should obey them. Thus there is a clear requirement to obey the Sanhedrin or Rabbinic authorities even if they tell you the opposite of what is or seems to be correct.
On the other hand the Yerushalmi(Horius 1:1) states, You might think that you must obey the [Sanhedrin or Rabbinic authorities] even when they tell you that "right" is "left" and that "left" is "right" –therefore the Torah says that you are to follow after them "right and
left". Thus it is only when they tell you that "right" is "right" and "left" is "left" that you should obey them. On the surface then it seems to be simply a dispute between the Babylonian and the Yerushalmi.
However Horious (2b) states that if a person knows the truth and yet follows the mistaken ruling of the Sanhedrin he must be a korbon as an act of repentance. Thus clearly the Bavli also requires that you do what
you think is right - even against the Sanhedrin.
An interesting and persuasive explanation is given by Rav Ovadia Yosef.
Rav Ovadia Yosef (Yabiah Omer Y.D. 6:7.2): … The Yerushalmi (Horious 1:1) states, that you might think even if they tell you that "right" is "left" and that "left" is "right" that they must be obeyed. Therefore the Torah says that you should only obey them if they say that "right" is "right" and "left" is "left". But this is the opposite of the Sifre [that you must obey them even if they tell you that "right" is "left" and "left" is "right"…. However according to the explanation of the Ramban (Sefer HaMitzvos Shoresh I) and those who support him [Ran Sanhedrin 87a] there is a reconciliation. According to the Ramban as long as the dissenting view has not been directly presented to the Sanhedrin [or Rabbinic authority] then he must refuse to eat that which the Sanhedrin insists is kosher. [If he eats food that he regards as unkosher because he is relying on the Sanhedrin he must bring a korbon] However once he has directly discussed the issue with the Sanhedrin and they have rejected his view [despite his best efforts] then the halacha becomes that he must obey them [even if he is still convinced he is right.]