Though improbable, is it technically possible for a layman to be elected pope?
Theoretically speaking, the office of pope is open to any Catholic man. (A woman could not be chosen because she is incapable of receiving ordination and the pope must be the Bishop of Rome.) Ordinarily speaking, the man chosen is a member of the college of cardinals. Should a non-ordained man be elected pope, canon law provides that he must be ordained to the episcopate.
The Roman pontiff acquires full and supreme power in the Church when, together with episcopal consecration, he has been lawfully elected and has accepted the election. Accordingly, if he already has the episcopal character, he receives this power from the moment he accepts election to the supreme pontificate. If he does not have the episcopal character, he is immediately to be ordained bishop (canon 332 §1, Code of Canon Law).
If he is a priest, he would automatically be ordained a bishop. If a deacon, he would first be ordained a priest, then a bishop. If a layman, he would be ordained deacon, priest, and bishop in rapid succession. (In such extraordinary cases, the bishop who ordains him would simply turn the page in the ritual book and begin the next ordination.)
For more information on the procedures of papal elections, please see the document linked below.
Universi Dominici Gregis by John Paul II