Pope Pius XII, Vacantis Apostolicae Sedis, Dec. 8, 1945: "34. None of the cardinals may in any way, or by pretext of any excommunication, suspension, or interdict whatsoever, or of any other ecclesiastical impediment, be excluded in the active and passive election of the Supreme Pontiff. We hereby suspend such censures solely for the purposes of the said election; at other times they are to remain in vigor (AAS 38 [1946], p. 76)."
It’s a dogma that 1) heretics are not members of the Church; and 2) that a pope is the head of the Church. It is a dogmatic fact, therefore, that a heretic cannot be the head of the Church, since he is not a member of it.
What, then, does Pope Pius XII mean in Vacantis Apostolicae Sedis? First off, one needs to understand that excommunication can be incurred for many things. Historically, excommunications were distinguished by the terms major and minor. Major excommunications were incurred for heresy and schism (sins against the faith) and certain other major sins. Those who received major excommunication for heresy were not members of the Church (as we have just proven at length). Minor excommunication, however, did not remove one from the Church, but forbade one to participate in the Church's sacramental life. Pope Benedict XIV made note of the distinction.
Pope Benedict XIV, Ex Quo Primum (# 23), March 1, 1756:
"Moreover heretics and schismatics are subject to the censure of major excommunication by the law of Can. de Ligu. 23, quest. 5, and Can. Nulli, 5, dist. 19."57