I'm focusing on the question why the opinion of the church changed in the past, not the "historic landmarks" (single events) that lead there.
I'd like to look on two periods in time:
Before AD 313 (edict of Milan)
The situation then was completely different than the situation today:
- There were many contradictory doctrines (example: Arian controversy) and unlike today there was no authority deciding which opinion was the "official one" when there were contradictory opinions.
So we cannot say which one was "the opinion of the church" when there were both voices favoring and rejecting capital punishment.
We know that many Christians in the first centuries saw military service as sin. Maybe they also saw capital punishment as sin. - People working in the legal system were (nearly only) non-Christians. So seeing capital punishment as "allowed" does not necessarily mean that Christians are allowed to be involved!
However the catechism (today) can only answer the question if Christians are allowed to be involved. - Other forms of punishment simply were not known or they were not feasible in that time (thanks Thunderforge for your comment)
After AD 385
According to Wikipedia no later than AD 380 the Roman government started to influence teaching of the church in major aspects. No later than AD 385 Christians having a different belief even were executed.
This means that Christian teaching was massively influenced by people we would call "politicians" today.
In later periods this was even worse:
In the medieval period for example bishops typically also were politicians. You might find this "polemic" but unfortunately they often adapted Christian teaching to their political interests and not the other way round. (There are for example paintings from that period showing this.)
Today
Today we have a completely different situation:
- The most important: Christian teaching is not influenced by political or other interests (at least I hope so)
- If the church would say: "Capital punishment is allowed" this definitely would mean: "Christians are allowed to be involved"
- There are other methods of punishment which work well
- Although there are many different opinions in the Catholic church (as a Catholic I know this!) there is an authority defining which of these opinions is the "opinion of the church" and which is not
This situation is different to the other two periods I mentioned.
I don't know if there were already times in history when we had this situation.
If no, the opinion of the church in earlier times is simply not comparable to the opinion of the church today because the situation of the church is a completely different one.
And the reason of the change of the opinion of the church is simply the change of the situation.
Some notes about my edits:
I removed the term "early church" from my answer because (according to some internet findings) this term is understood differently by different people.
I also apologize for the statement in my first answer which was understood in a way that I claim that the church today and the medieval church are not the same organization.
The sentence was not meant the same way as: "Australia and Austria are not the same country" but more like: "The USA under Trump and the USA under Obama are not the same country".