Before Angelo Cardinal Roncalli was validly elected pope in 1958, the last valid pope who used the name John was Pope John XXII (1316-1334). In 1410, Baldassare Cardinal Cossa was crowned antipope by cardinals who had deserted the rightful Pope Gregory XII. Cossa chose to be known by the name "John XXIII" but he was not a valid pope.
When Angelo Cardinal Roncalli chose the name of John after his valid election in the twentieth century, he was numbered John XXIII because he was the next valid pope with the name of John. Analogously, if a future pope chooses the name of Pius, he will be known as Pius XIII despite the fact that there is currently an antipope who has claimed the name “Pius XIII” for himself.
DISCLAIMER: Catholic Answers has turned over the archive to Catholic-Questions.org and no longer owns, manages, or moderates the forums. For additional apologetics resources please visit www.catholic.com.