24: In every season, Jack Bauer winds up doing everything he can in his power to stop the threat of the day and ultimately his efforts wind up costing him so much more personally. By the final season where we actually see him in a very rare spot of being content, he's become Genre Savvy enough to realize that helping to stop the current terrorist attack is going to naturally all but lead to this happening to him again and does his best to initially avoid being caught up in it. Ultimately he does wind up doing so, and true to form, by the final episodes this trope bites him back hard.
Angel: Angel has this happen as well, particularly in the 4th and 5th seasons.
Arrow: Most of the people who want to kill the Arrow have been saved by him.
In Auction Kings, Paul almost always fails to meet reserves. He does occasionally take them, but is very hesitant.
Murdock hears a dog whining in the bushes and leaves the car to pick it up, thinking that a driver hit it and then drove away. It's a trap on the part of the bad guys, who meet him with guns as he comes out of the bushes.
The whole episode is a large example of this trope, given that the trouble the team has could have been avoided had they not ruined the bad guys' businesses (presumably in the process of rescuing some of the past victims of the week.)
Bates Motel: Norma has gone through absolute hell trying to protect Norman and help him conquer his Sanity Slippage, but ends up murdered by his hand in the end.
The Big Bang Theory: Sheldon helped Penny go to the hospital by driving her. He runs a red light by following her instructions and gets a ticket. To fight the ticket, he has to miss a Stan Lee autographing session at the comic book store.
It doesn't end there. The ticket was sent to Penny originally since it was her car and license. However, she couldn't afford any more points on her license, so she threw Sheldon under the bus and told them he was driving.
Buffy the Vampire Slayer: Buffy's life runs on this trope. No matter what she does, the PTB find new ways to fuck with her.
Spike gets hit with a fair amount of this in Season Five. After realizing that he loves Buffy, he tries to be good to get her to take notice of him, but after having been evil for over a hundred years, he doesn't really understand what good is anymore. Most of his attempts at being good are rejected by Buffy because they don't fit human norms of what is good or because she is suspicious of him and his motives (with good reason). When he eventually starts to get better at his good deeds, he starts paying for them physically (gets savaged by a demon while helping Dawn, is nearly tortured to death by Glory for refusing to reveal that Dawn is the Key, gets his hands sliced open saving Buffy from a Knight of Byzantium), though Buffy begins to take him more seriously and his deeds finally pay off as he is more or less accepted by her and her friends.
In one episode of Castle, a secondary character named Simon Doyle saves Beckett and Castle's life, at which point Beckett puts Doyle under arrest for no discernible reason.
Gideon: Refresh me, Lieutenant. How did we get in the middle of this again? Matheson: I believe it was an act of mercy, Sir. Gideon: Remind me never to do that again. Matheson: Aye, Sir. No good deed goes unpunished. Gideon: I'll have that embroidered on a sampler when we have time.
Dexter: Dexter saves a man's life midway through season 4. That man kills Rita in the season finale, as well as several other people earlier. Subverted Trope, because Dexter saved his life so he could have the pleasure of killing him. However, in a more straight example, Dexter later stops Trinity from killing a young boy which is what drives him to kill Rita for revenge.
This show is stuffed with this trope. Even if the Doctor's help doesn't screw him at the time, it sometimes has ramifications in the timeline that he doesn't discover till later.
The Doctor, period. The guy goes around saving planets and has probably saved billions of lives at this point, but he himself has died 13 times, lost countless friends, and experienced more heartbreak and seen more horrific sights than any person ever should. It's a miracle he's as sane as he is.
A particularly sharp example is the Fourth Doctor story "The Face Of Evil", although it's not immediately obvious what's going on. It turns out the whole mess the Doctor finds himself in was in fact caused by himself, when he helped some colonists debug their computer. It wasn't a bug, it was a nascent AI, and he drove it insane by trying to fix it. On the meta hand, that good deed being punished led to Leela becoming his companion, and the dads of Britain rejoiced.
Series 9 is particularly bad about this. If the Twelfth Doctor hadn't saved — rather than destroyed — his home world of Gallifrey in the 50th anniversary showand saved Ashildr's life in a way that made her immortal earlier in this season, the plot against him that leaves him in a bespoke torture chamber would never have been hatched. And because Clara, inspired by the Doctor's example, will do anything — however reckless and risky — to protect the innocent Rigsy in "Face the Raven", she is Killed Off For Real. It's not surprising that the Doctor undergoes a severe Sanity Slippage in the following two episodes and temporarily becomes a Woobie, Destroyer of Worlds.
Frasier: One episode has the title character question whether it's good to be a Good Samaritan on the basis of how frequently his attempts to do good have backfired on him (note that the parable itself is not an example — we don't know what happens to the Samaritan afterwards).
Being merciful likely results in becoming a head shorter, as shown by Ned Stark who warned Cersei to save her children and refused to take Joffrey hostage which got him arrested and executed.
Daenerys believes this of Mirri Maz Duur's betrayal until Mirri points out that Daenerys' beloved husband was the cause of all her woes in the first place.
Jaime Lannister intercedes to prevent Brienne from getting raped, is spite of dueling with her just hours before. This compounds his captors' enmity, leading them to chop off his hand.
Hardcastle and McCormick: In the pilot episode, Mark McCormick steals a prototype car from the bad guy (who had killed the designer and forged legal documents in order to get his hands on it). In the ensuing Car Chase, a police car crashes and Mark comes to the rescue of the trapped cop...who gets a good look at Mark's face and (regretfully) has him arrested for the theft.
Heroes: Someone is helping Matt Parkman fix a tire; unfortunately, Sylar is possessing him at the time and kills the helpful man with a tire iron.
House: In the sixth season finale, House convinces a woman whose leg is trapped under a pile of rubble and whose life is endangered if they take too long to free her that she shouldn't let her leg be amputated. He sees parallels to the incident that ruined his own leg, where he made the same decision. However, after being called out by Cuddy, when she points out that his choice to refuse amputation has left him crippled, in pain, bitter, and alone, he convinces the woman to change her mind and performs the procedure himself. Everything seems fine... until, on the ride to the hospital, the woman succumbs to an embolism caused by the amputation, and House is powerless to do anything except watch her die. Later, Foreman tells him that he did the right thing, only for House to furiously assert that it doesn't matter because "she died anyway".
Freddie, every time he does a good deed, it bite's him on the ass later. In iSam's Mom, he catches an elusive criminal on video when no one else could. He's rewarded with nothing but a coupon (buy a dozen smoothies, get 10% off on your 13th), which expired the very next day. Then on national television, T-Bo and a female schoolmate reveal his full name and address while the crook is still on the loose.
Freddie and Carly pushing Sam to admit she's in love with Brad backfires hard in iOMG. Sam is actually in love with Freddie, and ends up doing a Forceful Kiss on him when he's trying to prod her into telling Brad. Considering Freddie has canonically loved Carly since he was about 10 years old, and Carly could be fighting her own feelings for Freddie, this could easily be very bad.
The Invisible Man: Darien Fawkes is a thief who has been in and out of prison for most of his life. While trying to rob yet another place, he comes upon an elderly guard, who faints. Believing the old man is suffering a heart attack, Darien has a choice: run with the loot, or try to save the guy. He starts trying to perform CPR on the guy, only to be caught red-handed by the other guards. The old guy later testifies in court that Darien tried to rape him. Cue life in prison without parole.
Season 5, Sayid (in the past) is locked in a cell awaiting execution. A young and at this point innocent Ben Linus who is sympathetic to Sayid steals a key and rescues him from his cell. After Sayid escapes, he repays Ben by knocking out a guard (Jin), stealing his gun, shooting Ben, and leaving him for dead. Sayid hates the adult Ben, but the child Ben was innocent and had just saved his life.
Also Ben (while some the deeds not necessarily being good) did everything Jacob told him to do without question and waited years to see him himself, and his reward for those years of loyalty? Watching Locke skipping the waiting list and seeing Jacob first time he asks.
In the episode "Mr. Monk and the Three Julies", a graduate student named Julie Teeger (who is not to be confused with Natalie's daughter) ends up getting a package meant to be delivered to a housewife of the same name by mistake, and generously delivers it to the rightful receiver. Unfortunately, that package contained evidence that the housewife's husband was unfaithful, so both Julies end up dead.
In "Mr. Monk on Wheels," Natalie basically spends an entire episode as the living embodiment of Nice Job Breaking It, Hero!, culminating in Monk getting shot in the leg.
Lampshaded by Regina in Once Upon a Time. After she watches Johanna get killed, she then tells Snow, "See where being good gets you?" And considering what Johanna's killer had put her through, she knows from experience.
She and Rumplestiltskin suffer from this in particular. Regina becomes a much better person, and what is her reward? Her True Love is killed in front of her eyes, again, and in such a way that he can never go to the afterlife. Rumplestiltskin sacrifices his own life to save his family and indirectly the town in season 3, and his reward? He is revived but then spends a year enslaved by Zelena with his son's mind trapped inside his own head, driving him insane. To top it all off, his beloved son, for whom he spent 300 years devising a curse just to get him back, dies in his arms. Whereas Zelena gets away with it. No wonder the two of them are so jaded.
In Orange is the New Black the inmates gaslighting Pennsatucky gets her sent to the psych ward. Piper feels bad for her, so she goes to the administration and takes full responsibility for the prank. Pennsatucky, who is released, ends up trying to kill Piper and exhibiting behavior of someone who probably should have stayed in psychiatric care.
The Outer Limits (1995): In "Small Friends", a prisoner who has secretly invented nanomachines uses them to aid a fellow prisoner in repairing a CD player he broke, which is owned by a hostile convict who will kill him if it isn't fixed. As a result of this act of kindness, the inventor has his secret exposed to the hostile con, is forced to aid that con's escape, and ultimately loses his life while defending his family from him. At least the nanomachines paid the con back for that one.
Ned attempts to undo the revenge taken by Chuck and Olive on Balsam's Bittersweets and gets arrested for murder as a result.
And once, when he was still a kid, he climbed up a tree for a kindergarten class to show them baby birds...but they were all dead. So he revived them, and showed the birds to the class...Then they decided to show him the three baby woodpeckers that they were going to release that day...
In episode 2, Charlie Matheson convinces Miles Matheson to not kill off the bounty hunter Jacob. While it is a good deed to not murder someone while he's helpless, it comes back to bite them in the rear when Jacob sells out their location to the Monroe militia.
In episode 4, Tom Neville gets trapped under rubble in a storm cellar. Danny Matheson could have easily just left Neville to die, because he's the bad guy who arrested him in the first place. However, he decides to do the right thing and save the guy's life...only to get arrested again.
In episode 11, Jason Neville warns Charlie about the air strike coming in 12 hours, and this is when he lost everything. Charlie thanks him for the information, but refuses to take him in, because he's part of the militia.
In episode 16, Charlie, Jason and Nora Clayton decide to free the scientist Ethan Camp and his family. That is a good deed, but then they find themselves facing the wrath of Tom Neville.
In the first season finale, Team Matheson finally gets the power back on for everyone worldwide. This is a good deed, but then Randall Flynn uses the opportunity to launch Intercontinental Ballistic Missiles to destroy Philadelphia and Atlanta. Not only that, but the American government that has been hiding out in Guantanamo Bay, Cuba, is now going to come in and retake what's theirs.
St. Elsewhere: Dr. Westphall decides to have the residents do community outreach around St. Eligius hospital through a community service program Dr. Ehrlich goes to work with inner city youths and gets mugged. Dr Chandler goes to work at a women's health clinic, which is bombed by protesters. The next day, a second bomb goes off at St. Eligius, injuring only him. Dr. Morrison goes to work at a prison clinic, and is raped by an inmate.
This is touched upon, where bad results sometimes come from good deeds, often as a result of completely unpredictable, Butterfly Effect-esque cause-and-effect actions. One character remarks that the universe is so complex, and so random, that instead of having complete control over the actual consequences of one's deeds the only thing one can control is "whether we are good or evil."
Orlin got a particularly raw deal when he descended to a mortal form in order to provide valuable intel on the Ori and helped to develop a cure for the Prior plague. For his troubles, he not only became trapped in his mortal form, but also suffered permanent brain damage, consigning him to spend the rest of his life (which is considerable, as he came back as a 12-year-old boy) in a sanitarium, and even worse, his memory is so far gone that when Sam goes to visit him, he doesn't even remember her.
The two-parter episode "Evolutions" has at least two examples: One was with a CIA agent named Burke who was Kicked Upstairs to an assignment in the worst possible location: Honduras. The reason he was exiled involved betrayal, but not as you might think: He actually killed the actual traitor, another fellow CIA agent named Woods, in self defense after he called him out on the action, but he took the fall for the sake of Woods' wife (had Woods been exposed as a traitor, his widowed wife would not receive pension). This was only mentioned and not explicitly shown. The second is a member of the anti Honduran extremist faction. He tried to side with Daniel Jackson about shutting off the Ancient healing device, as he's being creeped out by the device (and Jackson also explained that it should never be activated regardless of intentions). The leader responds by initially making it seem as though he is going to turn it off, but then unexpectedly shoots him and kills him. It gets worse in that he ends up being revived thanks to it being turned on, but his mind was permanently gone and thus was no different than a Zombie.
Starfleet Academy's famous Kobayashi Maru test is a no-win scenario where answering a distress call gets you blown up for your trouble. Only Kirk ever passed, and he cheated.
Of course "not answering the distress call" and "running away and leaving the Kobayashi Maru to die when you're getting beaten" are also options, so it's not just the good-deeds that lead to failure in that test.
There's a Next Generation episode called "Samaritan Snare". Guess what happens?
Geordi quotes this trope in "The Enemy", declaring it the motto of Galorndon Core. As the planet is perpetually covered by electrical stormclouds, allowing only intermittent transporter windows, with the rocky surface constantly faced by rain + storms, and pulling the injured Romulan to safety before he promptly makes him his prisoner 'again' despite this, it's completely fair.
In the dramatic climax of "Redemption", Worf spares the life of his enemy's son Toral, even though Klingon honor all but demands he kill the boy. Years later, Toral makes a surprise return on Deep Space Nine; instead of making something of his life, he's become as bad as his old man. He nearly succeeds in killing Worf and stealing the Sword of Kahless.
"No good deed ever goes unpunished" is the 285th and last Ferengi Rule of Acquisition.
Trip quotes the saying in Enterprise's "The Andorian Incident". The good deed in this case is paying a visit to a remote Vulcan monastery... which happens to have been taken over by Andorians, and the away team's arrival makes the situation even worse.
Except it results in them getting Commander Shran as an ally, which despite the problems he causes does Earth a lot of good in the long run. The act has serious consequences for T'Pol's career however.
In an episode on Tales from the Darkside we follow a young boy who has just lost his grandmother and fulfills her dying wish to save the family's souls from an ancient demon named the Cutty Black Sow. The boy does exactly as he is told by performing a ritual to keep it away, but then the demon shows up and takes his soul as compensation. The last shot of the episode has the demon cornering the little boy,going in to take his soul.
In Season 6 of The Walking Dead, Daryl sparing Dwight's life resulted not only in his bike and crossbow being stolen, but also indirectly led to Denise's death at the hands of the Saviors. Now, Alexandria has lost their only doctor and trained medic of any type, which is something they've been trying to avoid all season.
A constant theme, particularly with regard to the Baltimore Police Department. Any police character who sticks his neck out to try to do some good will be Reassigned to Antarctica, if not fired outright, for the sin of pissing off the bosses and/or the politicians.
Not so much a good deed as a competent one, but near the end of the second season, Ziggy finally loses the Idiot Ball and successfully disguises an inside job as a break-in. His reward is being conned out of $18,000. He doesn't take it well.
At the end of the first season McNulty is demoted for having brought several high-ranking members of the Barksdale Organization to justice (the reason being that the investigation stirred all kinds of trouble with the corrupt politicians).
Likewise, prior to the events of the show the highly competent Freamon had served 13 years (and 4 months) in the pawn shop unit for being good police.
Mayor Royce, upon finding out about Hamsterdam, initially lets it continue because it significantly decreased violent crime (although even this was self-serving). Said reaction was the main reason he lost the office to Carcetti.