The Vicar of Bray

 

In good King Charles' golden days,
When loyalty no harm meant,
A zealous High Churchman was I,
And so got my preferment;
To teach my flock I never missed,
Kings are by God appointed,
And damned are they that dare resist,
Or touch the Lord's anointed

High Churchmen were those who embraced the Roman Catholic elements in the Church of England - especially stressing elaborate ceremonial and the sacraments. In the reign of James I and Charles I, High Churchmen were the greatest supporters of royal power. (Puritans held Low Church principles and stressed preaching).
Preferment = career advancement.
The injunction not to touch the Lord's anointed is based on I Samuel 24, where David insisted that no hand should be raised against Saul, even when the King had acted unjustly
 

And this is the law, that I'll maintain,
Until my dying day, Sir,
That whatsoever King may reign
I'll be the Vicar of Bray, Sir-

The Church of England was governed and regulated by the King in Parliament. In Tudor and Stuart times, regimes in power could and did expel ministers who refused to conform to its religious and political edicts.
 

When Royal James possessed the crown
And popery grew in fashion,
The penal laws I houted down
And read the Declaration;
The Church of Rome I found would fit
Full well my constitution,
And I had been a Jesuit,
But for the Revolution

And this is the law, etc..

After the Restoration of Charles II a series of laws to enforce religious conformity were passed (in particular, the Clarendon Code of 1661-65 and the Test Act of 1673). These penal laws required that all holders of government jobs acknowledge the Royal Supremacy and take the sacrament of Holy Communion according to the rites of the Anglican Church. The laws were intended to exclude Roman Catholics and Protestant Nonconformists from public office.
James II was a Roman Catholic and in 1687, he issued a Declaration of Indulgence suspending the penal laws in an attempt to help his co-religionists. A number of prominent Anglican Clergymen, including the Seven Bishops refused to read the Declaration at Church Services as ordered.
Jesuit priests (members of the Society of Jesus) were known as the most fervent Catholics with an almost fanatical devotion to the Pope.
 

When William our deliverer came,
To ease the nation's grievance,
I turned the cat in pan again
And swore to him allegiance.
Old principles I did revoke,
Set conscience at a distance,
Passive obedience is a joke,
A jest is non-resistance.

And this is the law, etc...

To turn the cat in the pan is an old phrase meaning to change sides slickly and glibly.
Many of James II's supporters (and some of his opponents) refused to swear allegiance to William III, because they believed him to have usurped the throne. These "Non-jurors" (who included five of the Seven Bishops) lost their jobs.
Passive obedience was the idea that subjects should refuse to obey a royal command against divine law, but show their obedience by submitting to any punishment that resulted. Non-resistance was the doctrine that it was never legitimate actively to oppose the king. The two doctrines were key components of the the theory of the Divine Right of Kings.
 

When glorious Anne became our queen
The Church of England's glory,
Another face of things was seen,
And I became a Tory:
Occasional conformists base, I damned, and moderation,
And thought the Church in danger was,
From such prevarication.

And this is law, etc.

For much of Queen Anne's reign, the Tories were predominant in government and the nation. The Tory party wanted to preserve the Anglicans' monopoly of power. They were particularly angered by Dissenters who circumvented the penal laws by taking the sacrament in the Church of England only often enough to satisfy the legal requirements for office, whilst attending Nonconformist congregations for the rest of the time. The Occasional Conformity Act (1711) tried to end this form of evasion.
Those Anglicans who wanted to adopt a more conciliatory approach to Protestant Dissenters and modify the Church of England's services to satisfy them were known as Moderate Men. True Tories condemned them  for "giving up the Church, and sacrificing its order and constitution to peace and moderation." (A Letter to a Friend Concerning the New Distinction of High and Low Church, 1689)

 

When George in pudding time came o'er,
And moderate men looked big, sir,
My principles I changed once more,
And so became a Whig, sir;
And thus preferment I procured
From our great faith's defender,
And almost every day abjured
The Pope and the Pretender.

And this is the law, etc..

The reign of George I (the first king of the House of Hanover) began a long period of Whig ascendancy.
Pudding is the sweet course of a meal (dessert), and so pudding time was the part that everyone looked forward to.
George I was the first English monarch to use the title (Fidei Defensor) Defender of the Faith on his coins. (Ironically, the title had been given to Henry VIII by Pope Leo X for a polemical defense of the seven sacraments against Protestants).
The Oath of Abjuration was a solemn assertion made by all holders of government office repudiating the right of the Stuart Pretenders (James II's son, James Edward, and grandson Charles Edward) to the crown. It was imposed by law under William III and George I.
 

The illustrious house of Hanover,
And Protestant succession,
To these I do allegiance swear,
While they can keep possession;
For in my faith and loyalty
I never once will falter,
And George my lawful King shall be-
Except the times should alter.

And this is the law, etc...

In 1701, an Act of Settlement was passed to determine that the House of Hanover would succeed to the throne of England on the death of Anne. The Act also required that only communicating members of the Church of England should be allowed to ascend the throne. This requirement for a Protestant succession excluded not only the offspring of James II but other Roman Catholic descendants of James I.

 

Other Cavalier songs.
More on the Vicar of Bray and its context.