In Sefer HaIkkarim the following quote appears:
וזהו שאמרו שהנביא האומר לעבוד עבודה זרה אפילו לשעה אין שומעין לו. אבל אם יאמר שנחלל שבת או שנעבור על אחת מן המצות בהוראת שעה או בענין שלא יהרוס שרשי הדת, ראוי שנשמע לו משום שנאמר אליו תשמעון,
But that which is told to a person by God without the mediation of a prophet, no prophet has the power to abolish even temporarily. Hence the statement of the Rabbis, “If a prophet tells the people to worship idols, even temporarily, he must not be obeyed; but if he says that we should violate the Sabbath or transgress some one of the commandments as a temporary measure, or even permanently, provided he does not subvert the foundations of the religion, we must listen to him, because it says, “Unto him ye shall hearken.” (translation from Sefaria)
Where is this "statement of the Rabbis" found? The traditional sources allowing for a prophet to annul a command (besides idol worship) stress that it be temporary, not permanent (Yevamos 90b; Sifrei Devarim 175; Mishneh Torah Yesodei HaTorah 9:3).