In early times, the privilege of papal election was not reserved to the cardinals, and for centuries the person elected was customarily a Roman priest and never a bishop from elsewhere. To preserve apostolic succession the rite of consecrating him a bishop had to be performed by someone who was already a bishop. The rule remains that, if the person elected Pope is not yet a bishop, he is consecrated by the Dean of the College of Cardinals, the Cardinal Bishop of Ostia.
What happens if a Pope is elected who is not a bishop?
he is consecrated by the Dean of the College of Cardinals, the Cardinal Bishop of Ostia.