If prospective United Kingdom MPs must swear allegiance to the monarch, and if MPs are needed to change laws, how might the UK become a republic, assuming sufficient public support?
Another revolution, obviously. They did that in 1649.
Much more likely, they would politely inform the Queen that the people don't seem to want a Queen any more. If that is really the case, and not just a vocal minority, then after some polite back and forth the Queen would probably step down rather than fighting a civil war which she is unlikely to win.
While many Brits will be true to their oath, consider the difference between the individual monarch, the Crown, and the Crown-in-Parliament (which is a polite way of pretending that the monarch is still involved in legislation).
There is the quip what when it comes to dusty, centuries-old rights and prerogatives, the British monarch gets at most one try at overriding the elected government.
The Oath doesn't preclude republicanism.
(Subject to interpretation, of course.)
Note that the oath (or solemn declaration) only commits the MP to "true allegiance" to the reigning monarch of the day.
I (name of Member) swear by Almighty God that I will be faithful and bear true allegiance to Her Majesty Queen Elizabeth, her heirs and successors, according to law. So help me God.
It doesn't say anything about loyalty to the institution of the monarchy itself. So a republican would argue that they can faithfully take the oath, pay true allegiance to the Queen (or King) and subsequently disband the monarchy. In other words, their loyalty is to the individual, not the institution. They are committing not to undermine the Queen by attempting a coup to replace her with another monarch, not to work with foreign powers against her etc. But they can still disband the monarchy, and say that they've done right by the Queen up until the point where the monarchy no longer exists.
Of course, a monarchist would dispute this reasoning and say that all MPs are honour-bound to support the monarchy in all circumstances. Even if you take this interpretation of the oath, there are republican MPs in parliament so either they are dishonourable or the oath doesn't matter.
There are lots of republican MPs (probably including the Leader of Her Majesty's Loyal Opposition). Some of them have taken the Loyal Oath with their fingers crossed behind their backs.
At the moment, it's not worth campaigning for a republic because polls show that the public is overwhelmingly in favour of the monarchy. That could easily change when the Queen dies. At that point (if enough MPs were republican) they'd just invite the King to step down. If he declined, we would have a constitutional crisis (my guess is that he'd be told his "advisors" had advised him to step down, so he had).
In recent years the constitutional settlement seems to be that significant changes to the constitution require a referendum.
Now even supposing that all MPs took the oath of allegiance entirely literally. There would be no breaking of this oath in legislation to enable a referendum on the abolition of the monarchy. The citizens swear no oath of loyalty and could vote in a referendum to create a monarchy without breaking any oath.
This all assumes a fiction: that the oath of allegiance would prevent MPs from doing anything. In reality, the Crown must do as it is instructed by Parliament. If Parliament says "There is no Monarch" then that is the law, there is no question that a republican Parliament would not act based only on the oath of allegiance. Don't forget that many of the founding fathers of the USA had, at one point or another, sworn allegiance to the King. If the politics require it, the oath is pretty meaningless.
It is not at all clear to me that the oath is intended to be taken literally or that it precludes republican principles. For example, in order to be nationalized as a Canadian citizen one must swear loyalty to the Queen, but the Supreme Court of Canada has held that:
The reference to the Queen is symbolic of our form of government and the unwritten constitutional principle of democracy.
In particular, they explicitly said that it's fine for committed republicans to take this oath.
Of course Canada is not the UK and a citizenship oath is not the same thing as a parliamentary oath, but unless this issue has directly been addressed in the UK, it's entirely plausible that this oath does not, and is not intended to, preclude committed republicans from parliament.
As a side note, it's not actually correct that "prospective United Kingdom MPs must swear allegiance to the monarch". Elected MPs must swear allegiance to the monarch in order to take their seats in Parliament. But they can still be elected as MPs without swearing allegiance.
There's a long history of abstensionism by Irish Republican MPs elected in Northern Ireland who refuse to swear allegiance and don't take their seats in Westminster.
Since o.m.'s answer was apparently always intended to refer to the English Commonwealth, it may be worth keeping the events of the 1688-89 and the "Glorious Revolution" in mind.
In this case, an unpopular Head of State was (relatively bloodlessly) deposed and replaced by another, with the new head(or rather heads) of state and the legislature regularising each other's position in terms of English constitutional law. This somewhat circular argument gives an alternate example of how a British Republic could form without the Monarch's formal assent, and without the all out conflict of the English Civil War.
There is no one answer to this question, but one of the many available paths to a British Republic is the path of ‘peaceful legal revolution’ of the type described by the respected Mark Moshinsky (now a Justice of the Federal Court of Australia) in a 1989 paper (and others before and since). He did not in any way approach the subject of British republicanism (and even explicitly dodged Australian republicanism) but the methodology he describes certainly holds - just as it did for the Irish (1937) and Indian (1950) Constitutions which are both republican constitutions springing relatively peacefully from monarchical origins. It’s not just the oath of allegiance that must be ‘avoided’ - there are so many ways in which the nature of the British Parliament and the entire system of government are tied to the Crown. This to me makes ‘revolution’ an appropriate solution.
Moshinsky outlines the concept this way:
‘peaceful legal revolution' ... occurs when a new constitution is brought into existence by peaceful means, in circumstances which are not legal according to the preceding constitutional order, and the new constitution is effective in establishing a new constitutional order. There is thus a revolution in the legal order. This argument is based on an analogy with a successful violent revolution and assumes that a successful violent revolution can ultimately be effective in establishing a new constitutional order. The clearest example is the Constitution of the United States of America of 1788, which was clearly invalid according to British law, but is unquestionably constitutionally authoritative. It is suggested that it is possible to achieve the same result as a successful violent revolution, namely, the establishment of a new constitutional order, without the spilling of blood. The Constitutions of Ireland of 1937 and India of 1950 provide useful case studies to support this theory.
For example (crudely adapting some of what is said by Moshinsky, in the Australian context, to the British context instead), the British Constitution could be re-enacted by means of a peaceful legal revolution with the role of the Queen omitted and replaced with a non-executive President in place of the Crown. This would be complicated, of course, by the fact that the British Constitution is not in a single enactment and not even fully codified. But, assuming a complex amending instrument could be devised, the following scenario might be followed: the UK Parliament, after having secured popular approval, declares the Constitution to be amended in accordance with that instrument. The power to do so would be said to reside in the People, or perhaps the supremacy of Parliament to give affect to the Will and Authority of the People. A variant on this would be for the Parliament to follow the same course but call itself a Constituent Assembly to further distance itself from the preceding constitutional order. Alternatively the Irish example of 1937 could be followed whereby the People as a whole “amend” the Constitution. A slightly less dramatic method would be to follow the example of India, whereby the UK Parliament would adopt the instrument to amend the Constitution, declaring it to come into effect on a certain day and deliberately not seek Royal Assent (deliberately turning their backs on the old order in which the Crown is a constituent part of the Parliament).
Whichever method was followed, there would be a “technical” break in legal continuity. Saving provisions would be employed to minimise that break of course (to ensure old laws, and even constitutional conventions, remained in force, etc) but a re-born polity with links to the monarchy broken would be the result. Many might argue that a republic is always better “taken” by the People rather than “granted” to them by even a benign monarch and this methodology does, very politely, play into that symbolism of revolution.
: Moshinsky, Mark --- "Re-enacting the Constitution in an Australian Act"  FedLawRw 4; (1989) 18(3) Federal Law Review 134 but in particular page 146 onwards.
Oaths can be broken
Oaths can be broken, people sometimes do that. But violating an oath does not invalidate the voting power of the MPs.
If MPs vote to betray the monarch, that vote is valid. They may be considered as oathbreakers and that may have some consequences (for example, they might want to amend the laws on treason while they're at it), but that doesn't change the result, the vote would be binding anyway.