The saints and doctors of the Church teach that if a pope having sufficient knowledge and having made sufficient reflection denies an article of Faith and professes heresy, he falls to heresy and loses his papacy.
When it is taught that ‘a pope cannot profess heresy’ it simply means that this profession cannot be made and completed while he is pope, for upon attempting to profess heresy he loses his papacy and is reduced to a heretic, whereby the profession is made as a heretic and not as a pope.