The Conclave as we know today goes back to the Middle Ages, and was established to prevent a prolonged Vacant See (Sede Vacante) and outside interference.
Read more here: https://www.vaticannews.va/en/pope/news/2025-05/the-conclave-from-the-middle-ages-to-our-days.html