How did the papacy come into existence?
According to official Catholic doctrine the papacy has been in existence since the time of Jesus Christ. The Church holds that Jesus appointed the apostle Peter (now known as St. Peter) to be the first pope.
As the Christian church grew after Jesus' death, it came to be more organized, with various areas having bishops who led the faithful in those areas. Peter was the first bishop of Rome. All of his successors as bishop of Rome are now seen as popes.
It was not until some centuries after Jesus' death that the term "pope" came to be used only for the bishop of Rome. The bishop of Rome gradually came to have more and more power in the Church, first because of the importance of the city of Rome in the Roman Empire and later because of tradition.
So, you could say the papacy came into existence when Jesus called Peter his rock, or you could say the papacy came into existence gradually as the bishop of Rome came to have more and more authority in the Church.