Papal infallibility is a doctrine of the Church that says under certain conditions a pope will always be correct, and will be prevented from error by the Holy Spirit, when he speaks on a matter of faith or morals.
Although the tradition goes back to the early days of the Church, the conditions were laid out by the First Vatican Council in 1870 and are:
1. The pope is speaking or writing.
2. He is specifically speaking ex cathedra.
3. He is defining doctrine dealing with faith or morals.
4. His intended audience is the entire Church.
Ex cathedra means "from the chair." This means he is speaking from the chair of St. Peter as the pope.
So, infallibility has nothing to do with the pope's ideas on global warming, the best way to breed orchids, or who will win the Super Bowl. The subject matter must deal with faith or morals.
It also has nothing to do with the pope's personal conduct. Infallibility applies whether the pope is saint or sinner, since it is the Holy Spirit who is in charge of keeping him from error.
Since popes are infallible under the above conditions, the doctrine holds popes cannot contradict each other in infallible matters.
In The Templar Concordat, Cardinal Agretti will do anything to maintain this doctrine.