I think it certainly is not true that "if you write a good story, people won't care whose feet get stepped on". If, say, you paint the Catholic Church as totally evil, I think you're going to offend a lot of Catholics. Etc for any group.
If your goal is to paint some group as evil, if the purpose of your book is to expose how evil the Masons or the French or the bankers or whomever were, then you have to expect to offend people, and you can hardly claim to be deeply hurt that the people you are attacking are annoyed with you. But you seem to indicate that that's not your goal.
I think the solution most authors use is to just not bring the subject up. If you want to write a story set in the Balkans in the Middle Ages but you don't want to get into the morality of the Ottoman incursions, then just don't talk about it. Talk about the romance or the adventure story or the mystery or whatever it is you want to write about. If I was writing a murder mystery set in 21st century America and I didn't want to discuss, say, the relative merits of Republican versus Democrat politics, I don't think it would be hard to just not bring it up.
If you want to get into these subjects, another option is to explain why people did what they did. Like @VilleNeimei's discussion about torture. I read once that courts in the Middle Ages were very concerned about convicting an innocent person, and so they insisted on very high standards of evidence of guilt. But ... they thought the most convincing evidence was a confession, and confessions were often extracted with torture.
I'm not the first to say that it's easy to condemn others for prejudice, cruelty, and other evils when you haven't had to live through what they have. Like just recently I heard a tour guide in the Middle East ridicule the Crusaders for having no respect for the word of Muslims, for declaring that a promise made by a Muslim was worthless. But hmm, could that be because there were several incidents were Christians negotiated with Muslims, and the Muslims than broke their promises and took advantage of the agreement to kill the Christians? My point here isn't to attack all Muslims, but simply to say that if just a few months before a Muslim broke a peace agreement and killed all your friends, it is hardly surprising if today you don't trust Muslims, and for someone 1000 years later to say, "how terrible that they didn't trust people just because they had a different religion!" is just ... ignorant. The people at the time had very good reason not to trust these particular people.
What happens when everyone around you says that X is a good thing? If you thought it was wrong, but the government and your teachers and every book you read and your family and friends all say it's good, how many of us would just go along without thinking? Or say, Can it really be that I am right and everyone else in the world is wrong?
Some horrible behavior is prompted by ignorance. I mean literal ignorance: not knowing the true facts. For example, when the British arrived in Australia, it was widely believed that the Aborigines were not "fully human", that they were an earlier stage in evolution. And so many white people saw no more moral problem in taking their land than they would in driving away wild animals that occupied land where they wanted to build.
Another popular option is to portray individuals or groups as torn between good and bad impulses. I'm not a Catholic, and maybe a lot of Catholics would object to this characterization, but I think the Catholic Church started out as a very good organization. People respected them for their high moral standards, concern for the poor, etc. And so they build prestige and wealth and power. And then people came along who saw all that prestige and wealth and power and wanted in on it, and they infiltrated the organization and at many times and places took control of it. So there were competing forces: those who joined the church to further its original goals of preaching and teaching and helping, and those who joined as a route to wealth and power. You could certainly say similar things about almost any government. Etc.