If the church did change its doctrine, say the Pope spoke ex cathedra on the subject, could it be changed back with a new Pope.
Assuming an orthodox one was elected.
If the pope was not a Catholic, then in no way could he be the vicar of Christ, standing in for Christ as earthly head of Christ's Church, because it is impossible to be head of a body of which one is not a member himself.
The Vatican Council of 1870 in defining infallibility was firm that the charism adhered to the OFFICE of the Papacy. If an individual was to sin against the Faith as a private person, then BY HIS OWN ACT, he would fall from the Office of the papacy.
As for all the bozos since 1958, they have all been formal heretics BEFORE being elected so their elections were null and void from the start and they never possessed the Office. In the history of the Church there has never been a valid pope who became a formal heretic after being elected but if that were to happen they would fall from the Office by their own act of sin against the Faith.
Roman Catholic Church citations affirming this from another thread