Fr. Z.’s comments on who can be elected Pope are here. He has some good points. I’ll give a similar but more expansive answer.
The Pope is the Bishop of Rome; he is the head of the college of Bishops, but also himself a Bishop. So the person elected Pope must be either a Bishop or eligible to be elected Bishop. Since only males can be ordained as Bishops, the person elected Pope must be a male. As Fr. Z. says, a non-Bishop can be elected Pope and be ordained a Bishop after his election.
Pope-elect Stephen was a priest elected as Pope. He died days later, before he was elevated to the episcopal degree (i.e. made a Bishop), so he is called “Pope-elect” and not simply Pope Stephen. The Pope must be a Bishop.
There are a number of restrictions in Canon Law as to whom the Church may ordain as priest (and therefore also as Bishop). But I suppose most of these can be dispensed (if any were to apply) in the case of someone elected Pope.
The Apostolic Constitution of Pope Saint John Paul II, Universi Dominici Gregis, states three conditions for a valid Pope: “lawful election accepted by him, together with episcopal consecration.” — (1) a lawful election, (2) freely accepted by the person elected, (3) ordination to the episcopal degree. The Pope must be validly elected and must freely accept the office of the Pope.
Anyone incapable of meeting these conditions cannot be Pope. So if a person is a child, he does not have the maturity to accept his election with informed consent, so he cannot be Pope. History has seen child-kings, but never a child Pope. It is not possible.
Does he need to be a baptized Christian? This question is in the realm of the pure hypothetical. An unbaptized catechumenate would probably not have sufficient understanding of the Church, not having lived as a Catholic yet, to understand that to which he would be consenting. A non-Catholic Christian or a non-Christian (not a catechumenate) also might lack this ability to understand and therefore fully consent.
Suppose that an Anglican Bishop (recall that in the Catholic view Anglicans do not have valid Orders) were a recent convert to Catholicism, and that he has now been ordained in the Catholic Church as a Catholic Bishop. Such a person could be elected Pope. He meets all the criteria.
Father John Zuhlsdorf comments: “Also, some authors think that he cannot be a manifest heretic or schismatic, which seems reasonable, but not all writers think that’s a deal-breaker.”
My understanding is that the prevenient grace of God never permits any Pope to fall into apostasy, heresy, or schism. So what would happen, as a pure hypothetical, if a heretic were elected Pope? He could be a secret heretic, which would explain why the Cardinals would elect him. What would happen next?
One proposal (the “deal-breaker hypothesis”) is that the man would not really be the Pope. But since his heresy is hidden (an occult heretic is the term), no one would know. This idea cannot be correct because it would break the indefectibility of the Church. An apparent Pope who is not really the Pope would not have valid teachings, and any Council called and led by him would not be valid. The result would be that no one could be certain which Popes and Councils and teachings to trust. The Church’s teaching authority would be constantly suspect. Any proposed understanding of anything, which breaks the indefectibility of the Church, cannot be correct.
My proposal is that the prevenient grace of God absolutely prevents any Pope from falling into heresy, even in his heart and mind, even if he never teaches or expresses that heresy. The prevenient grace of God prevents all the holy souls in Purgatory from sinning in the least. The prevenient grace of God prevented the Blessed Virgin Mary from sinning for her entire life. It is possible for the prevenient grace of God to prevent each Pope from committing any sin of apostasy, heresy, or schism — for the sake of the indefectibility of the Church.
Does this act of God’s grace contradict the free will of the Pope? Not at all. For the Pope is only a valid Pope if he freely accepts his office, and he can freely resign at any time. As a result, by the grace of God, no Pope can ever fall into apostasy, heresy, or schism.
What if the man elected as Pope is already an apostate, heretic, or schismatic? I propose that when he freely accepts the office, the prevenient grace of God immediately and entirely vanquishes any or all of these three types of sins in his person, by virtue of his choice and the promise of Jesus that the Church would be indefectible. Thus, no Pope is ever a heretic.
If it seems to you that a particular Pope is teaching heresy, you are the one who has erred. The grace of God protects the Pope from falling into heresy, but you are free to do so, if you insist on committing that sin.
Please take a look at this list of my books and booklets, and see if any topic interests you.