The papacy in the modern age is typically associated with a grey-haired man of wisdom and experience. On average this has certainly been the case for the past 200 years.
According to I.Media, in the last few centuries, most popes have been in their 60s when they were elected:
Since 1800, the average age of a pope when he was elected has been almost 66.
The three oldest popes to emerge from the Sistine Chapel after the voting rounds were Benedict XVI (78), Francis (76), and John XXIII (76).
Pius IX, elected in 1846, was the youngest (54). John Paul II was 58 when he became pope.
However, this wasn't always the case as there are a few very young popes in the history of the Catholic Church.
The 20-year-old pope
The Catholic Encyclopedia explains that "The nephew of his two immediate predecessors, Benedict IX was a man of very different character to either of them...Regarding it as a sort of heirloom, his father Alberic placed him upon [the Throne of Peter] when a mere youth ... of about twenty (October, 1032).
He did not have a good reputation, and little is known about any official pontifical acts.
His papacy was marked by political controversy and much confusion. The Catholic Encyclopedia provides the following narrative of what happened:
Taking advantage of the dissolute life he was leading, one of the factions in the city drove him from it (1044) amid the greatest disorder, and elected an antipope (Sylvester III) in the person of John, Bishop of Sabina (1045 -Ann. Romani, init. Victor, Dialogi, III, init.).
Benedict, however, succeeded in expelling Sylvester the same year; but, as some say, that he might marry, he resigned his office into the hands of the Archpriest John Gratian for a large sum. John was then elected pope and became Gregory VI (May, 1045). Repenting of his bargain, Benedict endeavored to depose Gregory. This resulted in the intervention of King Henry III. Benedict, Sylvester, and Gregory were deposed at the Council of Sutri (1046) and a German bishop (Suidger) became Pope Clement II.
According to the Vatican website, he reigned a total of three separate times.
Benedict IX was not an example of a holy and virtuous pope who led the Church with moral clarity.
While he might be listed as one of the "bad popes," he did not officially teach any theological error, thus preserving the magisterial teachings of the Catholic Church.
He may have been named to the papacy for the wrong reasons, but the Holy Spirit still preserved the Church and prevented any harm to occur to its central teachings.
This is one of the mysteries of papal infallibility -- that a bad pope is not able to change Church teaching.