Sanhedrin (90a)R. Abbahu said in R. Johanan's name; In every matter, if a prophet tells you to transgress the commands of the Torah, obey him,18 with the exception of idolatry; should he even cause the sun to stand still in the middle of the heavens for you [as proof of Divine inspiration], do not hearken to him.
Ramban (Bereishis 15:14): … When a person kills because of an order from a prophet then he is only doing what is required of him. Therefore if he obeys because he wants to fulfill the will of G d then there is no sin in the killing and in fact it is considered a meritorious act. However if he heard the command of the prophet to kill but he killed out of hatred then he is punished because he intended to do a sin and his compliance with the prophet is considered a sin… Thus we know that Nevuchadnezzar heard that all the prophets had said that he should go and destroy Yerushalayim. He and his entire people were commanded to do this by the prophet… Nevertheless they were eventually punished. There were two reasons for this punishment. 1) His intent was not to fulfill the command of the prophet but it was to destroy the land of Israel and thus increase the size of his empire…2) Because he caused the Jews to suffer much more than he had been commanded.
Radvaz (2:652): Question: We have an established principle that if an established prophet should command us to transgress one of the mitzvos of the Torah except for idolatry we are to listen to him. For example Eliyahu on Mt. Carmel transgressed on the command not to offer sacrifices outside of the Temple. He didn’t do this to nullify the mitzva but rather as an emergency measure to refute the prophets of Baal. Your question is whether such a prophet said to kill someone or destroy a particular city or to pillage a particular city as an emergency measure to protect the Torah – how can we obey such a command since no court would do such a thing even as an emergency measure? And even if it were commanded by G d – but we have the principle of “it is not in Heaven”? Since a person is not killed except with witnesses and with proper warning – how is it possible to listen to the prophet to transgress that which is stated in the Torah? Even if he gives an explanation for the need to do this – that would not be sufficient – but he says it is a mitzva to listen to him according to the Torah. Answer: Also in my eyes this is was puzzling until it occurred to me to say that this principle only applies to mitzvos between man and G d. But concerning mitzvos between men, there is no command to listen to him. However I saw in Sanhedrin (90a): Concerning all sins if a prophet tells you to transgress the words of Torah you are to listen to him except for idolatry, because it is possible that he has the ability to stop the sun in the middle of the sky so don’t listen to him…. Thus this gemora clearly states that the only sin not to commit at the command of a prophet is idolatry. … So since it is explicitly stated that it is a mitzva to transgress when commanded by a prophet…. therefore even to kill a person would be required or to destroy a particular city. This is similar to the statement that “I heard that one flogs and punishes not according to the law of the Torah but for the emergency needs of the times and to save the Torah and its mitzvos.
Mishneh Torah, (Foundations of the Torah 9:3) When a prophet - who has already proven himself to be a prophet - instructs us to violate one of the mitzvot of the Torah or many mitzvot, whether they be of a severe or light nature, for a limited amount of time, it is a mitzvah to listen to him. The Sages of the early generation taught as part of the oral tradition: If a prophet tells you to violate the precepts of the Torah as Elijah did on Mount Carmel, listen to him with regard to all things except the worship of false gods. This applies when his command is temporary in nature. For example, on Mount Carmel, Elijah offered a sacrifice outside [the Temple's premises], even though Jerusalem was chosen for such [service], and one who offers a sacrifice outside [the Temple's premises] is liable for karet. Since he was [already established as] a prophet, it was a mitzvah to listen to him. The commandment, "Listen to him," applies in these circumstances as well. If they would have asked Elijah: How can we violate the Torah's command [Deuteronomy 12:13]: "[Be careful...] lest you offer your burnt offerings everywhere"?, he would have told them: We should not say anything, but anyone who offers a sacrifice outside [the Temple premises] is liable for karet, as Moses said. [The present instance,] however, [is an exception]. I am offering a sacrifice today outside [the Temple] at God's command in order to disprove the prophets of Ba'al.
Similarly, if any [other] prophet commands us to transgress for a limited time, it is a mitzvah to listen to him. If, however, he says that the mitzvah has been nullified forever, he is liable for execution by strangulation, for the Torah has told us: "[It is] for us and our children forever."
The above is apparently contradicted by the following
Yermiyahu (35) The word that came to Jeremiah from GOD in the days of King Jehoiakim son of Josiah of Judah:
Go to the house of the Rechabites and speak to them, and bring them to the House of GOD, to one of the chambers, and give them wine to drink.
So I took Jaazaniah son of Jeremiah son of Habazziniah, and his brothers, all his sons, and all the men in the household of the Rechabites;
and I brought them to the House of GOD, to the chamber of the sons of Hanan son of Igdaliah, the agent of God, which is next to the chamber of the officials and above the chamber of Maaseiah son of Shallum, the guardian of the threshold.
I set bowls full of wine and cups before the Rechabites, and said to them, “Have some wine.”
They replied, “We will not drink wine, for our ancestor, Jonadab son of Rechab, commanded us: ‘You shall never drink wine, either you or your children.
Nor shall you build houses or sow fields or plant vineyards, nor shall you own such things; but you shall live in tents all your days, so that you may live long upon the land where you sojourn.’
And we have obeyed our ancestor Jonadab son of Rechab in all that he commanded us: we never drink wine, neither we nor our wives nor our sons and daughters.
Nor do we build houses to live in, and we do not own vineyards or fields for sowing;
but we live in tents. We have obeyed and done all that our ancestor Jonadab commanded us.
But when King Nebuchadrezzar of Babylon invaded the country, we said, ‘Come, let us go into Jerusalem because of the army of the Chaldeans and the army of Aram.’ And so we are living in Jerusalem.”
Then the word of GOD came to Jeremiah:
Thus said GOD of Hosts, the God of Israel: Go say to the citizenry of Judah and the inhabitants of Jerusalem: “You can learn a lesson [here] about obeying My commands—declares GOD.
The commands of Jonadab son of Rechab have been fulfilled: he charged his children not to drink wine, and to this day they have not drunk, in obedience to the charge of their ancestor. But I spoke to you persistently, and you did not listen to Me.
I persistently sent you all My servants, the prophets, to say: ‘Turn back, every one of you, from your wicked ways and mend your deeds; do not follow other gods or serve them. Then you may remain on the land that I gave to you and your ancestors.’ But you did not give ear or listen to Me.
The family of Jonadab son of Rechab have indeed fulfilled the charge that their ancestor gave them; but this people has not listened to Me.
Assuredly, thus said the ETERNAL, the God of Hosts, the God of Israel: I am going to bring upon Judah and upon all the inhabitants of Jerusalem all the disaster with which I have threatened them; for I spoke to them, but they would not listen; I called to them, but they would not respond.”
And to the family of the Rechabites Jeremiah said: “Thus said GOD of Hosts, the God of Israel: Because you have obeyed the charge of your ancestor Jonadab and kept all his commandments, and done all that he enjoined upon you,
assuredly, thus said GOD of Hosts, the God of Israel: There shall never cease to be someone from the line of Jonadab son of Rechab standing before Me.”