That's interesting! Catholics tend to avoid using heretical names. In fact, I believe that it's in canon law that baptismal names cannot be the names of heretics, and that it is the priest's duty to prevent such a name from being used. So it is very strange that any pope would the name of a known heretic.
So why do we have two popes with the name of a heretic, and a very recent one, at that? Perhaps it is because Pelagius of the heresy himself might have denied important aspects of that heresy:
This theological theory is named after Pelagius, although he denied, at least at some point in his life, many of the doctrines associated with his name. (Wikipedia)
Still it is strange, because the name would still have been associated with the heresy. So let's look further. From Wikipedia:
Beginning in the sixth century, some popes adopted a new name upon their accession to the papacy; this became customary in the 10th century, and every pope since the 16th century has done so. [...] During the first centuries of the church, the bishops of Rome continued to use their baptismal names after their elections. The custom of choosing a new name began in AD 533 with the election of Mercurius.
It is because "Pelagius" is the original name of both popes! 1
- Mercurius becomes Pope John II in 533 (first change)
- Pelagius becomes Pope Pelagius I in 556
- Pelagius becomes Pope Pelagius II in 579
- Practice becomes customary circa 1000
It's still a question exactly why neither chose to follow the example set by Mercurius (named after the Roman god Mercury), but I suppose the practice was only taking root around that time.
1: This is not certain, but seems very probable: the name-changes of other popes around that time are well-recorded but no change is recorded for either of these popes, and I can find no record of either Pelagius being called by a different name before becoming pope.