But then you must also admit the Church stumbles on occasion, which is rather the point here. I don’t really hold the Church in any special contempt over its conduct in the Middle Ages. It was a major religious and political institution populated by people of similar upbringing and views as their secular/temporal counterparts. There was a time when the Church was not adverse to the execution of heretics. Yes, in many cases it tended to try to get the heretic to at least publicly recant, but at the same time it sent many heretics to their doom, and within the Papal States the Church was the government, and the executions of heretics there was done by the Church.
But the Church, as with much of Western Civilization, changed its views on such practices. To some extent, the Church’s position was altered for it. The loss of the Papal States essentially ended the Church as a significant political power in Europe, and thus its ability to impose itself even within its own neighborhood came to an end. It no longer had the actual ability to impose any kind of sentence. With the Lateran Treaty, the Church’s actual sovereignty became limited to Vatican City.
In other regards, like the change in tact by the Church on the topic of democracy was really a shift within the upper echelons of the Church hierarchy to the fact that democracy was becoming the norm and that many Catholics had every expectation that they should be able to have the political voice that comes along with the right to vote. I’d say all in all the Church did an admirable job shifting to being more fully a spiritual institution and abandoning any desire or ability to exercise any kind of political control.
That all being said, whether many of my fellow atheists like it or not, the Church was very much a critical institution in the Middle Ages. It gave at least Western Europe some veneer of unity even as princes battled each other for territory and influence. For some time, it was the chief source of scholastic preservation and progress, and the history of the era is littered with priests in the courts of kings, princes and emperors serving as advisers, bureaucrats, record-keepers, and so forth. Without the Church’s at least somewhat calming and unifying influence, the Germanic princes that ended up ruling much of Western and Central Europe would have probably plunged the continent into a true dark age.