In the middle ages there were priests and deacons who received the office of Cardinal and thus were able to be elected pope but I do believe they were ordained if they were chosen or else they couldn't hold the title of Bishop of Rome.
This is correct. In fact, theologians hold that if such a one would refuse to be ordained and consecrated, that would be considered tactic refusal to accept the office. Yes, theologians considered such a scenario. Basically, the candidate is more of a pope-elect. If a bishop were to accept, he'd immediately become pope. But if a non-bishop were to accept, he would remain in a pope-elect type of state until actually getting consecrated. To be the pope, you have to be bishop of Rome, so if you refuse to be a bishop, it's the same as refusing the papacy.
Let's just say that I and most theologians disagree with the statement purportedly from Pius XII that such a one would receive the gift of infallibility. You cannot teach the Church unless you're part of the
Ecclesia Docens, and only bishops are part of this "Teaching Church". On top of that, jursidiction cannot be held by someone who isn't at least a cleric. So I think Pius XII misfired there.