It is generally accepted that students deserve to be tested on their knowledge under conditions that are known sufficiently in advance to allow them to prepare effectively. Coming to class and being told you have to take an exam right that minute when you were previously led to expect a different testing scenario very obviously does not meet that convention.
Simply put, your professor messed up, and in my opinion it is a no-brainer that you (and any other student who wishes to) should be allowed to retake the exam.
Edit: several commenters seem to interpret OP’s story as reflecting poorly on them and their level of preparedness, and seem to be implying that OP is somehow “not worthy” of having their complaint taken seriously. One of them said outright that OP “deserve[s] to fail the test anyway”. I am baffled by such victim-blaming: almost everyone seems to agree that the professor’s unannounced change to the exam schedule and procedures was unfair, and this unfairness was inflicted on the entire class. What difference does it make whether OP is a top student or on an underperforming student who would likely have failed the exam even under ideal conditions? The unfairness is the same, and the remedy is also the same: both the top student and the underperforming one should be given an option to retake the exam.
But let’s assume for a second that OP’s detractors have a point and that their judgment of OP’s command of the material is both correct and relevant. In that case, I would argue, it is even more important that they be allowed to retake the exam. The reason for this is that it is only after doing poorly on a fair exam that a student will have to confront the reality of their poor learning choices and poor knowledge of the material, and face their situation with a clear mind: they will not have any excuses then to cover up for their poor performance. And it’s only after giving a fair exam that the professor can in good conscience assign a failing grade to a student, and that the university can ethically demand that the student improve their performance or suffer negative consequences to their status in the program. The ability to take an exam under fair testing conditions is not some kind of reward for good behavior; rather, it is an absolute necessity for the credibility of the entire system.
The bottom line is, any way one looks at it — whether as a supporter or a detractor of OP, as a skeptic or a believer — one has to reach the same conclusion. As I said, it’s a no-brainer.