Can a simple layman (Catholic who is not a deacon, a priest or a member of a religious order) be elected pope? Theoretically, yes. Although, in practice, it is something very rare and extremely unlikely to happen.
In the entire history of the Church, very few laypeople have been chosen to be universal pastors of the Church. If I’m not mistaken, there are only four cases: Hadrian II (867 to 872), Leo VIII (pope from 963 to 965 – there are doubts whether his election was legitimate), Benedict VIII (pope from 1012 to 1024) and John XIX (pope 1024 to 1032).
Some experts say Benedict IX was also a layman, but the issue is controversial.
Soon after their election, those laypeople had to receive the three degrees of the Order on the same day, one after the other, before ascending to the Peter’s Throne. Admit it: your definitions of “that day was loco” have been updated successfully! In a single day the guy became a deacon, priest, bishop and pope!
This is because every pope must also be a Bishop of Rome. The current code of canon law states that if the elected pontiff is not a bishop, he must immediately receive this ordination (can. 332).
The idea of the election of a layman as pope is not just strange today, but also to Catholics of those times. Hadrian II himself was so amazed by his election that he refused to be pope on his occasions, and only accepted the mission the third time he was elected.
On the other hand, it was quite common for antipopes to be laymen (antipopes were shameful popes, elected by rulers and others powerfully in an invalid way).
The fact is that, with each new conclave, what is expected is that the pope will be selected from the restricted group of cardinals of the Church. And cardinals are almost always bishops – but, from time to time, priests are elected as cardinals as well.
Under canon law, cardinals are also the only ones who can vote in the conclave for the election of a new pope.