However, in 1685 Charles II died and James II succeeded. In 1687 he replaced Ormonde with Richard Talbot and introduced a policy of replacing Protestant officers with Catholic ones in the Irish Army. Mountjoy was one of few Protestants remaining in the army and he could protect his Protestant soldiers and officers, such as Lundy.

The Apprentice Boys of Derry shut the gates of the city against "a regiment of twelve hundred Papists, commanded by a Papist, Alexander Macdonnell, Earl of Antrim",[3] who hastily withdrew his small force. Later, the Viceroy solicited intervention by Mountjoy and finally dispatched a strong but poorly disciplined Irish force commanded by Sir Richard Hamilton to march north against the Protestants.[4]

A stratagem prepared by Mountjoy and Lundy to assume control of Derry succeeded in embedding a small garrison of predominantly Protestant troops under the command first of Mountjoy then of Lundy, who assumed the title of governor.[5] However, popular feeling in Derry ran so strongly in favour of the Prince of Orange that Lundy declared himself an adherent of King William III, and he obtained from him a commission confirming his appointment as Williamite governor of Londonderry.

From December 1688 to March 1689 Lundy had the walls and the gates repaired to protect the city, refitted gun carriages and musket stocks, removed buildings and dungheaps outside the walls which might provide cover to besiegers, purchased powder, cannonballs and matchlocks, and had a protective ravelin and outworks built.[6][7]

Lundy's motivation cannot certainly be known. What is certain is that from the moment Derry was threatened by the troops of King James, Lundy used all his endeavours to paralyse the defence of the city. In April 1689 he was in command of a force of Protestants who encountered some troops under Richard Hamilton at Strabane, when, instead of holding his ground, he told his men that all was lost and ordered them to shift for themselves; he himself was the first to take flight back to Derry. King James, then at Omagh on his way to the north, similarly turned in flight towards Dublin on hearing of the skirmish, but returned next day on receiving the true account of the occurrence.[8]

On 14 April English ships appeared in the Foyle with reinforcements for Lundy under Colonel John Cunningham and Solomon Richards. Lundy dissuaded Cunningham from landing his regiments, representing that a defence of Derry was hopeless; and that he himself intended to withdraw secretly from the city. At the same time he sent to the enemy's headquarters a promise to surrender the city at the first summons. As soon as this became known to the citizens, Lundy's life was in danger, and he was vehemently accused of treachery. When the enemy appeared before the walls Lundy gave orders that there should be no firing. But all authority had passed out of his hands.

The people flew to arms under the direction of Major Henry Baker and Captain Adam Murray, who organized the famous defence in conjunction with the Rev. George Walker. Lundy, to avoid popular vengeance, hid himself until nightfall when, by the connivance of Walker and Murray, he made his escape in disguise.[9]

traditional effigy of Robert Lundy in Londonderry prior to being burnt by the Apprentice Boys

He was apprehended in western Scotland, imprisoned at Dumbarton Castle,[10] and then sent to the Tower of London. He was excluded from the Act of Indemnity in 1690. An effort was made to send him for trial at Derry, but this was argued against because it was evident that Lundy still retained the support of influential people there. As Reverend George Walker described this, "he had a faction for him" in the town.[11] After an enquiry in London he was "cleared of charges of treason" and returned to military service.

From 1704 to 1712 he was "Adjudent-General of the King of Portugal's forces in the Queen of England's pay" during the War of Spanish Succession[12]where he defended Gibraltar against the French[13]. In 1707 he was captured by the French, but was exchanged a year later.[14]

Lundy is reviled in Ulster loyalism to this day as a traitor and is burned in effigy during the celebrations to mark the anniversary of the shutting of the gates of Derry in 1688. A 'Lundy' has also become a byword for traitor for unionists and loyalists. Ian Paisley regularly denounced many people, including Prime Ministers Margaret Thatcher, Captain Terence O'Neill and First Minister David Trimble, as "Lundies".

^Childs 2007, p. 71 top: "Robert Lundy was born in Dumbarton and raised in the Church of Scotland. During the 1670s he served in the Earl of Dumbarton's infantry regiment in French service ..."

^Childs 2007, p. 71 bottom: "Lundy married Martha Davies, daughter of the Reverend Rowland Davis, later Dean of Cork, and exploited her connections with the Duke of Ormonde to secure promotion on to the Irish establishment as lieutenant colonel ..."

^Macaulay 1855, p. 143/144: "a regiment of twelve hundred Papists commanded by a Papist, Alexander Macdonnell, Earl of Antrim, had received orders from the Lord Deputy to occupy Londonderry."