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.
Happens constantly to Jon Snow in A Song of Ice and Fire. Actually happens to just about everyone in his family for that matter. And most people in Westeros.
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, and he was forever branded with the title "Kingslayer".
Elphaba in the book version of Wicked 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 also indirectly 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...
Glinda gets hit with this even earlier on when all of her 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 The Wheel of Time, most characters after their heroics are punished accordingly by their local female authority, i.e. Aes Sedai, Wise Ones, Maidens, wife.
Fighting Fantasy was notorious about the "magical beggar" trope. Virtually every beggar you would meet would give you help that is far more valuable than the single coin you had to donate to them. In one book this is explained by the generosity of your donation: sure, you give a single gold piece every time, but the standard currency for those parts is copper.
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 Dresden could be the poster child for this trope. No matter how many times he saves the world, no matter how many times he does the right thing, breaking even is coming out ahead for him. And he doesn't come out ahead very often.
For example, 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."
And let's not forget poor Murphy. In Proven Guilty, she 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.
In The Bible, 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.
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 expreimented 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.
In Harry Potter, Dumbledore takes an orphaned boy off to Hogwarts and gives him an education in magic. That boy grows up to be Voldemort. He does the same thing for Harry, of course, and this causes less disaster (eventually); though his attempts to protect Harry lead to some nasty things, particularly Sirius's death. Harry gets a Deed of his own in the end of book 4: he and Cedric end up cooperating to finish the final task in the Triwizard Tournament, so Harry convinces him that they should take the Cup simultaneously and become co-victors. They are unexpectedly whisked off to a graveyard in the middle of nowhere, and Cedric, who was not part of the bad guys' plan, is pointlessly executed. If Harry had been selfish and taken the Cup for himself, Cedric would have survived...and he could have told Dumbledore about the Portkey, possibly giving him a chance to prevent 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 Mc Pherson (nicknamed Maggie Mc Fierce) 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.
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.