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.
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.
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.
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.
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.
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).
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.
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.
The Outer Limits: In "Small Friends," an episode of the revived series, 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 and the surface is hot and rocky, this is 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.
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 of The Wire, 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.