To Kill a Mockingbird, by Harper Lee, where the whole story revolves around a good deed that is punished, namely the protagonist's father, a defense attorney, making the unpopular decision to defend a black man who has been falsely accused. Even more so the reason that the black man is in trouble in the first place was because he did a number of good deeds for a troubled young white woman because he felt pity for her.
Justine, by the Marquis de Sade, is an incredibly over-the-top rendering of this trope, with the title character's virtue and good deeds rewarded with the worst kind of abuse and suffering throughout her life. And considering that the author's name is where we get the word "sadism," we have a clear picture of just how bad things get for her.
And of course Jaime Lannister, who, despite being a member of the Kingsguard and sworn to protect the king, killed the Mad King Aerys to prevent him from murdering every person in King's Landing. Unfortunately, no one understood why he did it (or cared), and he was forever branded with the title "Kingslayer".
Ned Stark tries to prevent Queen Cersei and her three children's deaths by warning her to run away, as he has learned her dark secret, and he knows the king will have them all executed. Her answer is to capture him, have him painted as a traitor and force him to accept being separated from his entire family, while keeping his eldest daughter as a prisoner.
Elphaba starts out trying to do good. She ends up getting killed off for real by the end of the book because of it. (The musical version has much more family friendly ending for her though she's still blamed for everything)
Glinda suffers from this trope, since her attempt to help Dorothy by giving her the ruby slippers only contributes to Elphaba's eventual nervous breakdown when she hexes the ruby slippers so they won't come off Dorothy's feet, which keeps Dorothy from giving them to Elphaba...which could very well have kept Elphaba from lighting her broom, and... well...
All of Glinda's attempts to help Elphaba be a better and happier person not only fail, but take a toll on her social circle and emotional well-being, and are possibly what help drive Elphaba on a more radical course. It's implied that the adult Glinda is something of a drunk specifically because of this.
In The Sound and the Fury, Quentin finds a young girl who is unable to speak English and he realizes that she is probably lost. Quentin proceeds to buy her some food and spend the next few hours trying to find her family. His thanks for this is an arrest from the police, who were summoned by the young girl's older brother who thought that Quentin was kidnapping the girl. Quentin is fined seven dollars for this 'crime'.
Anita Blake quotes the saying in her first book, Guilty Pleasures: "He had to be stopped. If I hadn't interfered tonight, he would have been stopped. No good deed goes unpunished."
Harry's unwillingness to let evil triumph because he refused to save someone started a war that caused an uncertain (but extremely high) number of deaths and made him even more of a social pariah among the wizarding community than he was before.
Probably the clearest example is when one of Harry's enemies gifts him his own tombstone. It reads "Harry Dresden: He died doing the right thing."
In Proven Guilty, Murphy abandons an investigation to help Harry save a teenage girl who is the daughter of a genuine Knight in Shining Armor, by going through the heart of Winter itself, with no guarantee that she'll come out alive, the odds stacked against her. She doesn't even hesitate to help. Her reward? A demotion, and a warning that she'll get fired if it happens again. As of Changes, she is fired. For exactly the same reason.
Jesus resurrects the dead, feeds the hungry, heals the sick and disabled, teaches the way of the right and has done no wrong. He becomes hated by the Pharisees and is put on the cross.
Proverbs 17:13 denounces this:
Whoso rewardeth evil for good, evil shall not depart from his house.
The Legend of Drizzt: Drizzt's good deeds in the early part of his life caused him no small amount of grief. During his first surface raid he spared the life of a little elf girl and faked her death. Unfortunately, Lolth knew about this and didn't like that he wasn't an Ax-Crazy child murderer. She demanded a sacrifice from his house, and his father Zaknafein sacrificed himself in Drizz't's place. When the little elf girl he spared grew up, she mistakenly blamed Drizz't for the massacre that claimed her family that night due to her trauma. She spent her entire life hunting him and nearly killed him only to die in the attempt. Then there was the time he stumbled upon a gang of barghest whelps that had murdered a farming family and avenged them by killing the whelps. This earned him misplaced blame for the murders (as a Drow, he was a prime suspect) and the ire of a persistent bounty hunter. This trend more or less ended after he met his True Companions, who made sure Drizz't would get better PR.
In Honor Among Enemies, Warner Caslet is the captain of a light cruiser in the navy of the People's Republic of Haven. Haven has recently suffered a coup d'etat and is now ruled by a vicious, bloodthirsty regime which not only kills the officers who fail in their assignments, but shoots their families for good measure. When he is dispatched to the Silesian Confederacy as a scout for a commerce raiding operation that will prey on the merchant shipping of the Star Kingdom of Manticore, which Haven is at war with, he discovers a batch of home-grown pirates who are sadistic on a whole new level, capturing merchant ships even when they know they will not be able to take any captured cargo with them and torturing/raping the crew en masse. Caslet manages to convince his Peoples Commissioner that these pirates deserve to be caught, even if it is not in their orders to do so, and eventually tracks down their ship. However, the pirates are in the midst of capturing another freighter, and this one is a Manticoran ship, which Caslet has standing orders to capture himself. Caslet knows that there is a good chance that his ship will be destroyed if he decides to engage the pirates, and his own superiors might very well execute him on general principles if he risks his command to save a ship belonging to an enemy nation, but his personal integrity will not allow him to stand by and he again convinces his Commissioner to allow an intervention...then the Manticoran "freighter" he was trying to save revealed that it was a disguised warship and ended up capturinghisship. He avoids his government's wrath over this due to a legal loophole (All the officers claimed that the Manticoran freighter was flying under Andermani colors at the time in their reports, and his orders stated he was to assist Andermani ships), only then to end up earning the personal displeasure of a dubiously sane member of the Committee of Public Safety for showing basic decency to prisoners of war.
Michael (and Michael alone) is a frequent victim of this in the Knight and Rogue Series. Trying to save a 'kidnapped' woman gets Michael arrested, taking the fall for another man gets him flogged, letting Fisk escape Ceciel's guards gets him experimented on, refusing to arrest an innocent woman gets him marked unredeemed, stopping a man from beating a young boy gets him arrested-again, helping to put out a fire gets him chased by a mob, helping arrest a murderer gets him kicked out of town, and trying to save a man who's falling gets him accused of murder. As Fisk says, heroism is vastly overrated.
Dumbledore does his best to protect Harry and makes sure he survives, despite knowing that his wanting him safe instead of prepared for things will lead to horrible results. The worst being Sirius' death, which almost broke Harry. Consequently, Dumbledore has to call himself out while explaining everything to Harry.
Harry gets his own in Goblet of Fire, when he and Cedric are near the Triforce Tournament cup. Harry suggests they both take the cup at the same time, making both of them winners. The cup was a Portkey and transported both to a graveyard. Cedric gets killed, Harry tortured and almost killed himself, and Voldemort gets resurrected. Had Harry selfishly chosen to take the cup himself, Cedric would have survived... and could have run off to inform Dumbledore about the Portkey, likely preventing Voldemort's resurrection.
In Michael Connelly's The Reversal, Jason Jessup's defense attorney complained to the judge about the prosecution only releasing part of the data they intend to use against Jessup. Prosecutor Margareth McPherson (nicknamed Maggie McFierce) replied they were still within the deadline and suggested the defender believed no good deed should go unpunished.
The Sherlock Holmes story "The Gloria Scott" has Holmes' friend's father escape from a convict ship, but turn back to save a man's life... only for him to blackmail his rescuer and ultimately drive him to suicide.
In Across the Universe, the book ends with Amy and Elder dismantling the machine that pumps tranquilizers into the water supply, giving the people of Godspeed back their emotions. The sequel describes in disturbing detail how this leads to mass suicides, panic attacks, riots, and overall dissent.
In The Black Cauldron, Taran gives up his magical brooch to "buy" the titular cauldron, only to find out it can't be destroyed without letting someone willing die. Eilonwy tries to comfort him by pointing out that while he doesn't have the brooch anymore, no one can take away the fact that he did something truly honorable. And then he is pretty much forced to give up that very thing, when the only person around to help move the cauldron only will do so on the condition that Taran lie and say the other person found and retrieved the thing.
Taran is hit with this later on when his refusal to fight dirty or kill downed enemies results in the death of one of his beloved mentors (and numerous other village people as well). Of course it's eventually averted, since it's precisely the fact that Taran becomes willing to put Honor Before Reason and do good despite the cost that makes him worthy to draw Dyrnwyn in the last book.
In Peter Blauner's Man of the Hour, the main character saves a class full of students from a bomb on a school bus but becomes implicated in the subsequent investigation, turning his life upside down and forcing him to clear his name by finding the real bomber.
"Here lies Sam Flood/ Whose nature bid him/ To do much good/ Much good it did him" reads the writing on the wall in The Stranger House. Generally considered a saint, everyone is queuing up to take the credit for driving him to suicide. It turns out that he was murdered. For trying to get justice and care for a little girl who was raped and then sent to Australia to hush up the crime.
In Hannu Rajaniemi's The Quantum Thief, giving money to a beggar triggers a stampede of them.
In The House of Night, Stevie Rae saves Rephaim's life. In the end, this small act is the catalyst for Stevie Rae's boyfriend Dallas to go over to the dark-side when he finds out she's been hiding him this whole time. Stevie Rae is also Mistaken for Cheating.
In 11/22/63, the time-traveling protagonist goes through a great deal of trouble to stop the Kennedy assassination, in the belief that doing so will make the world a better place. Instead, it causes major damage to the fabric of time, and leads to an even bleaker future.
The sports-themed gamebook Defending Champions (from publishers of the "Which Way" series) gives you a choice about whether or not to punish one of your team for violating curfew. If you decide to let him off the hook, this leads to a Non-Standard Game Over. This act of clemency leads other players to think you're not cracking down on curfew violators and sets off a chain reaction that leads to you losing complete control of team discipline.
The 1986 Disney storybook "Thumper's Little Sisters" has Thumper saving his sisters from a vicious dog. His mother and father yell at him though in spite of his sisters standing up for him. Why? Thumper ended up leading the dog back to their burrow!
Space Wolf: Grey Hunter, naturally, this being the Crapsack World of Warhammer 40,000. During a Chaos-instigated rebellion on a world in the Wolves' territory, Ragnar's squad rescues a planetary defense forces unit that stayed loyal to the Empire. Their reward? A deep mind-probe by an Inquisition psyker (to be doubly sure of their loyalty) that kills one and ages the others a few years.
Darius from The Hunger Games. He steps in to try and prevent Thread from whipping Gale to death. He gets knocked out and later made into an Avox by the Capitol.
In Dorothy Dunnett's King Hereafter, Thorfinn decides that it would be a good idea to take in a number of Normans on the run from England. They later kill the only heir of a neighboring lord, leading to an understandable Roaring Rampage of Revenge and preparing the way for Thorfinn's own death.
In The Dinosaur Lords, Karyl and Rob manage to turn a battle their dumb superiors put them into from an unquestionable disaster to a draw that actually favours their side, and get arrested for treason for their trouble.
I Am Mordred: After Mordred frees the hawk, it kills Nyneve (and thus Gull, who's her familiar), since it's really Merlin transformed.
Central to the setting of The Fifth Season are Orogenes, who have the ability to, among other things, calm the constant seismic activity that plagues the world. When an orogene uses their abilities to save their family and neighbors from an earthquake, the survivors' first order of business is often to track them down and kill them out of fear and prejudice.
The Andalites in Animorphs named their version of the Prime Directivethe law of Seerow's Kindness after this trope. Seerow was an explorer who found a primitive yet intelligent race of symbionts, and gifted them knowledge and technology. These Yeerks then began a conquest of the Galaxy, enslaving or killing millions.