Wikipedia's article on this topic is a pretty good place to start, and for in-depth treatment, you'll want By Man Shall His Blood Be Shed (Feser and Bessette; in favor of the death penalty) and Capital Punishment and Roman Catholic Moral Tradition (Brugger; against). Also useful is Laurence's "He Beareth Not the Sword in Vain," a 2003 article on the subject.
To distinguish this answer from these works, I'll focus on summarizing key landmarks in the history of the Church's views on this subject. I'll rely primarily on Feser, Bessette, and Laurence – unfortunately Brugger's work isn't available to me, but thankfully Feser and Bessette interact with and quote him.
Church fathers widely accepted the legitimacy of capital punishment, though they varied in their views on how extensively it should be used. Feser and Bessette view it as a major concession that Brugger, an opponent of the death penalty, is forced to admit:
For the Fathers of the early Church, the authority of the state to kill malefactors is taken for granted. Opinions differed on whether Christians should hold offices whose responsibilities include the judging and carrying out of capital punishments—pre-Constantinian authors said they should not, those writing after AD 313 said they should—but the principled legitimacy of the punishment itself is never questioned (74)
Feser and Bessette cite a number of examples, including Ambrose (Letter 90 / 25, to Studius), Chrysostom (Homilies on the Statues, 6), Augustine (City of God 1.21), and Jerome (Commentary on Jeremiah, Book 4, on 22:3). Also significant is the writing of Pope Innocent I, who refused to condemn Christian civil authorities who carried out the penalty:
About these things we read nothing definitive from the forefathers. For they had remembered that these powers had been granted by God and that for the sake of punishing harmdoers the sword had been allowed; in this way a minister of God, an avenger, has been given. How therefore would they criticize something which they see to have been granted through the authority of God? (Epistle 6, to Exsuperium)
Some opposed the death penalty more intensely, like Tertullian, but even he, say Feser and Bessette, did not oppose it in principle, but rather only that Christians should not participate in it (De Idolatria 19). (Incidentally, in the same work, Tertullian also taught that Christians should not be school teachers).
In the medieval era, a few landmarks are worth noting.
First, Pope Nicholas I (d. 867) urged civil leaders to avoid using the death penalty, but did not call it illegitimate:
Just as Christ led you back from everlasting death . . . to eternal life, so you yourselves should save not only those who are innocent, but truly also the guilty from the destruction of death. (Epistula XCVII, quoted in Laurence)
Second, major theologians and canonists affirmed the legitimacy of the state exercising capital punishment, including Gratian, Aquinas, and Duns Scotus. Gratian writes:
It appears therefore that by means of men bearing lawful power . . . wicked men are not only scourged for their sins, but they are also properly put to death. (Decretum, Part II, Cause 23, Question 5)
Aquinas deals with this in his Summa, Book II-II, Question 64, Article 2:
Therefore if a man be dangerous and infectious to the community, on account of some sin, it is praiseworthy and advantageous that he be killed in order to safeguard the common good, since "a little leaven corrupteth the whole lump" (1 Corinthians 5:6).
Third, in the context of the readmission of heretics to the Catholic Church, Pope Innocent III, in 1210, required that former Waldenses affirm that "the secular power can, without mortal sin, exercise judgment of blood." This is significant, Feser and Bessette argue, because it suggests that acceptance of the death penalty was a necessary component of Catholic orthodoxy.
Reformation era to mid-20th century
The "Roman Catechism" of the Council of Trent addresses this issue in the context of Ten Commandments, and says:
Another kind of lawful slaying belongs to civil authorities, to whom is entrusted power of life and death, by the legal and judicious exercise of which they punish the guilty and protect the innocent.
In the 19th and 20th centuries, popes exercising civil authority did not oppose the practice. Giovanni Battista Bugatti was the official executioner for the Papal States from 1796 to 1865, and put hundreds to death. Regarding more recent times, Cardinal Avery Dulles writes:
The Vatican City State from 1929 until 1969 had a penal code that included the death penalty for anyone who might attempt to assassinate the pope ("Catholicism and Capital Punishment")
At least two encyclicals of this period support the legitimacy of the practice, Pastoralis Officii (1891) and Casti Connubii (1930), and Pius XII in several addresses in the 1950s supports it, perhaps most famously saying:
Even when it is a question of the execution of a man condemned to death, the State does not dispose of the individual’s right to live. It is reserved rather to the public authority to deprive the criminal of the benefit of life when already, by his crime, he has deprived himself of the right to live. (1952 address to the first International Congress of the Histopathology of the Nervous System)
Late 20th-century to today
In the latter half of the 20th century, movement against capital punishment became more pronounced around the world, and leading Catholics expressed their opposition as well. The United States Conference of Catholic Bishops called for abolition in 1974, for example, and respected Franciscan Gino Concetti wrote against the penalty in 1977.
More recently, two popes in particular – John Paul II and Francis I – have made statements regarding capital punishment that seem, to some, to indicate a shift in the Church's view on capital punishment. Feser and Bessette describe three positions in an ongoing debate in Catholicism: is it a reversal of traditional Catholic doctrine, a development of doctrine, or a prudential judgment of doctrine? The different sides of this debate disagree on the strength of tradition outlined above (can it be contradicted by a pope?), and on the interpretation of the teachings of popes John Paul II and Francis.
Several significant landmarks of this period occur during John Paul II's papacy – the publication of the Catechism of the Catholic Church in 1992, the encyclical Evangelium Vitae in 1995, and the updated Catechism published in 1997.
In 1992, the Catechism upheld the legitimacy of the death penalty but argued for limited use of it:
For this reason the traditional teaching of the Church has acknowledged as well-founded the right and duty of legitimate public authority to punish malefactors by means of penalties commensurate with the gravity of the crime, not excluding, in cases of extreme gravity, the death penalty. [...]
If bloodless means are sufficient to defend human lives against an aggressor and to protect public order and the safety of persons, public authority should limit itself to such means, because they better correspond to the concrete conditions of the common good and are more in conformity to the dignity of the human person.
In 1995, John Paul II's encyclical emphasizes the content of this second portion, saying that cases requiring capital punishment today are "very rare, if not practically nonexistent," but never explicitly rejects the legitimacy of capital punishment. This lead to an update to the Catechism, in which the first sentence quoted above is replaced as follows:
Assuming that the guilty party’s identity and responsibility have been fully determined, the traditional teaching of the Church does not exclude recourse to the death penalty, if this is the only possible way of effectively defending human lives against the unjust aggressor.
During the papacy of Benedict XVI, the Compendium of the Catechism of the Catholic Church was issued (2005). It follows the 1997 catechism, and cites the "very rare, if not practically nonexistent" language of Evangelium Vitae, but again does not call the practice illegitimate. Also in 2005, the USCCB published A Culture of Life and the Penalty of Death, reiterating its call for the abolition of capital punishment in the United States, and in 2009, a synod of African bishops supported universal abolition.
With the papacy of Pope Francis, the issue came to the forefront again. He publicly expressed his support for the abolition of the death penalty in 2013 and 2014, and in 2015 used even stronger language:
Today capital punishment is unacceptable, however serious the condemned’s crime may have been. [...] The death penalty is contrary to the meaning of humanitas and to divine mercy, which must be models for human
justice. (letter to the International Commission against the Death Penalty)
This has culminated in the 2018 revision to §2267 of the Catechism, which calls the death penalty "inadmissible" but uses language that suggests that support for abolition is at least partially based on the existence of "more effective systems of detention," and does not explicitly state that capital punishment is inherently immoral. Additional explanation from the Vatican on this change is available in its Letter to the Bishops; it explicitly calls the change a "development of doctrine that is not in contradiction with the prior teachings of the Magisterium."
Through the years, the Catholic Church has consistently taught that the State legitimately holds the power of capital punishment, though its support for implementation of the practice has varied. In recent decades, limiting and abolishing the practice has become a point of emphasis. Some have contended that this represents a reversal of church doctrine, but the Vatican and others contend that it is a merely a development in doctrine. Regardless, the practice has never been explicitly condemned as inherently immoral by an official publication of the Church, not to mention an ex cathedra statement.