The Magisterium of the Church has declared that the elevation of a heretic to the Papacy is invalid and null.
Pope Paul IV Cum Ex Apostolatus OfficioApostolic Constitution
6. In addition, [by this Our Constitution, which is to remain valid in perpetuity We enact, determine, decree and define:-] that if ever at any time it shall appear that any Bishop, even if he be acting as an Archbishop, Patriarch or Primate; or any Cardinal of the aforesaid Roman Church, or, as has already been mentioned, any legate, or even the Roman Pontiff, prior to his promotion or his elevation as Cardinal or Roman Pontiff, has deviated from the Catholic Faith or fallen into some heresy:
(i) the promotion or elevation, even if it shall have been uncontested and by the unanimous assent of all the Cardinals, shall be null, void and worthless;
(ii) it shall not be possible for it to acquire validity (nor for it to be said that it has thus acquired validity) through the acceptance of the office, of consecration, of subsequent authority, nor through possession of administration, nor through the putative enthronement of a Roman Pontiff, or Veneration, or obedience accorded to such by all, nor through the lapse of any period of time in the foregoing situation;
(iii) it shall not be held as partially legitimate in any way;
(iv) to any so promoted to be Bishops, or Archbishops, or Patriarchs, or Primates or elevated as Cardinals, or as Roman Pontiff, no authority shall have been granted, nor shall it be considered to have been so granted either in the spiritual or the temporal domain;
(v) each and all of their words, deeds, actions and enactments, howsoever made, and anything whatsoever to which these may give rise, shall be without force and shall grant no stability whatsoever nor any right to anyone;
(vi) those thus promoted or elevated shall be deprived automatically, and without need for any further declaration, of all dignity, position, honour, title, authority, office and power.