The Act of Settlement of 1701 expressly forbids any monarch or anyone in the line of succession in Britain from being Catholic. This happened because of several factors at the time. Queen Anne had at least 18 pregnancies, but one child survived - her son William, Duke of Gloucester. Unfortunately he died at the age of 11. Britain enacted a law which would continue the line of succession, but disallow any Catholic from taking the title. Anne's father, King James II of Britain and his children were removed from the line of succession.
The relevant section of the Act reads:
That all and every Person and Persons that then were or afterwards should be reconciled to or shall hold Communion with the See or Church of Rome or should professe the Popish Religion or marry a Papist should be excluded and are by that Act made for ever to inherit possess or enjoy the Crown and Government of this Realm and Ireland and the Dominions
Therefore anyone who is Catholic or marries a Catholic is prohibited from being the monarch of the United Kingdom. It's important to note that this law has not been repealed, although several attempts have been made to do this.