Q. How can a Pope be uncanonically elected?
A. One method is if he is a mason or belongs to a banned secret society.

The original banning of Catholics from joining masonry was given by Pope Clement XII In eminenti apostolatus specula issued on 28 April 1738.
It was re-iterated numerous times including in Humanum Genus, a papal encyclical by Pope Leo XIII on April 20, 1884.
In the 1917 Code of Canon Law, membership in freemasonry was explicitly named and forbidden by excommunication in code article 2335.

In 1983, a new edition of Canon Law was released. This one omitted naming masonry by name. It used generic words. Some think this meant joining freemasonry is permissible but it’s not. Generic wording was used to include other secret societies who work against the Church but who are not affiliated with masonry. Canon Law 1374 of the 1983 edition replaces article 2335 of the 1917 edition.

It reads: “Can. 1374 A person who joins an association which plots against the Church is to be punished with a just penalty; however, a person who promotes or directs an association of this kind is to be punished with an interdict.”1

The confusion lead to a clarification document in 1983 by Joseph Ratzinger [later Pope Benedict 16] and it reads:

It has been asked whether there has been any change in the Church’s decision in regard to Masonic associations since the new Code of Canon Law does not mention them expressly, unlike the previous Code.

This Sacred Congregation is in a position to reply that this circumstance in due to an editorial criterion which was followed also in the case of other associations likewise unmentioned inasmuch as they are contained in wider categories.

Therefore the Church’s negative judgment in regard to Masonic association remains unchanged since their principles have always been considered irreconcilable with the doctrine of the Church and therefore membership in them remains forbidden. The faithful who enrol in Masonic associations are in a state of grave sin and may not receive Holy Communion.

It is not within the competence of local ecclesiastical authorities to give a judgment on the nature of Masonic associations which would imply a derogation from what has been decided above, and this in line with the Declaration of this Sacred Congregation issued on 17 February 1981 (cf. AAS 73 1981 pp. 240-241; English language edition of L’Osservatore Romano, 9 March 1981). In an audience granted to the undersigned Cardinal Prefect, the Supreme Pontiff John Paul II approved and ordered the publication of this Declaration which had been decided in an ordinary meeting of this Sacred Congregation.

Rome, from the Office of the Sacred Congregation for the Doctrine of the Faith, 26 November 1983.
Joseph Card. RATZINGER Prefect

Given the clarification by Pope Benedict XVI when he was prefect, a mason is excommunicated and therefore Canon 1331 and Canon 1332 apply. Most specifically Can.1331.3 and Can.1332.4: CENSURES

Can. 1331 §1. An excommunicated person is forbidden:
1/ to have any ministerial participation in celebrating the sacrifice of the Eucharist or any other ceremonies of worship whatsoever;
2/ to celebrate the sacraments or sacramentals and to receive the sacraments;
3/ to exercise any ecclesiastical offices, ministries, or functions whatsoever or to place acts of governance.

§2. If the excommunication has been imposed or declared, the offender:
1/ who wishes to act against the prescript of §1, n. 1 must be prevented from doing so, or the liturgical action must be stopped unless a grave cause precludes this;
2/ invalidly places acts of governance which are illicit according to the norm of §1, n. 3;
3/ is forbidden to benefit from privileges previously granted;
4/ cannot acquire validly a dignity, office, or other function in the Church;
5/ does not appropriate the benefits of a dignity, office, any function, or pension, which the offender has in the Church.

By their very nature, secret societies do not advertise who their members are. The point of the above is that it is possible for a person to hide critical details about their associations in banned groups and hold a position within the Vatican, even as Pope, that is not valid.

There have been a few anti-popes and heretical popes in history which have been defrocked once their actions to undermine the Church surfaced and were confirmed. This final one is the worst ever and because people’s knowledge and love of their faith has dwindled, the false prophet will meet little resistance.