"Galileo was not punished by the church for saying the earth orbits the sun. Galileo was indicted and punished by the church because he was a local elite with several personal and political enemies within the church, and more directly, because he slighted the pope, his former friend, by taking a philosophical argument made by said pope, and putting it, paraphrased, into the mouth of a character in his book who was named "simplicio" and cast as a moron."

This is not really true. While there is some truth to the claim that Galileo placed an argument made by Urban VIII in the mouth of Simplicio and that Urban took offense at this, the trial documents, especially Galileo's sentence, make it very clear that Galileo was being punished for heresy and the heresy he was being punished for was the notion that Sun did not move and that the Earth did. From the sentence:

> We say, pronounce, sentence, and declare that you, the abovementioned Galileo, because of the things deduced in the trial and confessed by you as above, have rendered yourself according to this Holy Office vehemently suspected of heresy, namely of having held and believed a doctrine which is false and contrary to the divine and Holy Scripture: that the sun is the center of the world and does not moved from east to west, and the earth moved and is not the center of the world, and that one may hold and defend has probable an opinion after it has been declared and defined contrary to Holy Scripture.

Note that the term "vehemently suspect" is technical term. The Roman Inquisition in the 17th century didn't generally deliver straight up and down guilty or not-guilty verdicts and rather organized convictions according to degrees of suspicion. "Vehement suspicion" indicated that there was at least some (but not much) degree of plausible deniability that Galileo didn't believe what he had written, and that was only because Galileo denied it to the court.

"That pope literally gave him permission to publish his claim that the earth orbited the sun, a claim which Galileo did not make based on science, but instead made because he felt the resulting (incorrect and based on outdated observations) mathematical model for the orbits of planets was more "elegant"."

No, Galileo was given permission to publish a book that presented a neutral comparison of the Copernican and Ptolemaic models on mathematical grounds with the intention of proving that the Church was justified in its suppression of Copernicanism. Galileo's book was not neutral--it argued heavily in favor of Copernicanism--and that's why he got in to trouble. Urban VIII had been his friend prior to this episode so it's likely that had Galileo not placed Urban's argument in Simplicio's mouth at the end that Urban would have protected him rather than punished him, but the reason that Simplicio was given that argument was because that argument was intended to be the end of the book. After four days of continuously losing the debate, Simplicio finally raises Urban's argument about the omnipotence of God and his opponents are forced to agree with him. The idea being that Galileo could stick to the letter of his remit, while still arguing what he wanted. Unfortunately he argued too well and readers realized where is real sympathies lay. Urban VIII was accused of protecting heretics (not just Galileo, but also but supporting the French against the Hapsburgs in the 30 years war,) and so he made an example of Galileo.

Galileo's arguments were not simply mathematical. In fact, if they were, he would never have been punished because it was already permissible to treat Copernicanism as a purely mathematical hypothesis; the 1616 prohibition of Copernicanism explicitly carved out that exception. But Galileo used a wide variety of arguments, including physical arguments. Galileo after all, was primarily what we would call a physicist rather than an astronomer. It was Galileo's insistence that Copernicanism must be physically true and not just a better mathematical model that made him a heretic in the eyes of the Sacred Congregation.

It's important to note that the quality of Galileo's scientific arguments were never a subject of his trial. It was only his conclusions that the Sacred Congregation took issue with. Galileo's chief (but not only) argument, from the tides is now considered to have been spectacularly wrong, but at no point did that come up in the trial. Galileo's arguments could have been 100% perfect and unassailable (and scientific arguments rarely are) and he would have still been punished.

"If the church truly wanted to punish him, they would not have sentenced him to literally stay at home in a beautiful villa and write books all day."

He was sentenced to life imprisonment. That was commuted to house arrest on account of his old age and not at his own house at first. He was prohibited from receiving medical attention late in life. All books by him were placed on the index and he was prohibited from taking visitors. He did manage to continue his work, but that was by publishing in the Netherlands which was a Protestant country and hence outside the reach of the Church. He had first tried to publish in Venice which was a hotbed of anti-clericalism and usually Inquisitorial orders, but even they would publish him.

"His official charge was that lay people are not allowed to interpret the scripture, which he did a bit in his book."

That was not the official charge. I quoted the official charge above. Galileo's interpretation of scripture happened much earlier and preceded the 1616 prohibition of Copernicanism. There Galileo gave counter argument as to why Copernicanism didn't contradict scripture and that served as the catalyst for the investigation that led to the prohibition. Galileo ultimately was not censured for writing on scripture and his argument was even well received to a degree (he had checked it with a cardinal before publishing it,) but the Sacred Congregation decided that it was more concerned about undermining the authority of the Church Fathers, many of whom took the famous passage from Joshua literally, than it was about accidentally hooking scripture to a provably false view of the world. If you read Cardinal Bellarmine's response to Foscarini regarding Galileo's letter, you'll see him very clearly cite the authority of the Church Fathers as his primary consideration. Bellarmine controlled the Sacred Congregation at the time so his opinion on the matter was the Church's opinion.

"The church did not care if you made mathematical or scientific arguments about how the world worked.T hey only cared that you leave theology to the priests. "

The decree from the Index of Forbidden Books banning Copernicanism:

> This Holy Congregagtion has also leaned about the spreading and acceptance many of the false Pythagorean doctrine, altogether contrary to Holy Scripture, that the moves and the sun is motionless, which is also taught by Nicolaus Copernicus' On the Revolution of the Heavenly Spheres and by Dieage de Zuniga's On Job. This may be seen from a certain letter published by a certain Carmelite Father, whose title is Letter of the Reverend Father Paolo Antonio Foscarini, on the Pythagorean and Copernican opinion of the Earth's Motion and the Sun's Rest and on the new Pythagorean World System in which the said Father tries to show that the abovementioned doctrine of the sun's rest at the center of the world and of the earth's motion is consonant with the truth and does not contradict Holy Scripture. Therefore, in order that this opinion may not advance any further to the prejudice of the Catholic truth, the Congregation had decided that the books by Nicolaus Copernicus and by Diego de Zuniga be suspended until corrected; but of the Carmelite Father Paolo Antonio Foscarini be completely prohibited and condemned; and that all other books which teach the same be likewise prohibited, according to whether the present decree it prohibits, condemns and suspends them respectively.

Note that Diego de Zuniga and Paolo Foscarini are both priests. This wasn't about keeping theology to the priests, it was about prohibiting certain theology that would undermine the authority of the Church. The correction applied to Copernicus's book is that it be changed to suggest that his system was not intended as a literal interpretation but only as a mathematical model. As I mentioned earlier, an allowance for treating with Copernicanism as a pure mathematical contrivance for the convenience of astronomers was made but treating it as literally true was declared "error", and later upgraded to "heresy" during Galileo's 1633 trial.

Sorry for the essay, but this subject is a pet-peeve of mine.

Some good books on the subject:
1. Behind the Scenes at Galileo's Trial - Richard J, Blackwell
2. The Essential Galileo - Maurice A. Finocchiaro
3. Galileo Heretic - Pietro Redondi