There's a Donald Duck cartoon short where Donald gives an ant a bit of sugar out of kindness. In return for his good deed, the ants invade his house for more and eventually cause it to blow up, presumably killing Donald.
In a similar vein, the episode "Can You Spare a Dime?" of Spongebob Squarepants features Squidward quitting his job over a misunderstanding. When he ends up losing his house, SpongeBob selflessly takes him into his own home, and takes care of him. Squidward "thanks" him by becoming a freeloader, forcing SpongeBob to wait on him hand and foot, and throwing violent tantrums when he does not comply to Squidward's whims to every detail.
In "Porous Pockets", SpongeBob gets his hands on a fortune and generously buys ice cream for a stranger. Cue an enormous crowd of moochers skulking for free money until SpongeBob is bone dry.
A similar thing happens in "The Sponge Who Could Fly" where SpongeBob uses his flying pants to perform heroic deeds but the citizens of Bikini Bottom quickly become dependent on him for more or less everything so when he tries to escape they hunt him down because he "owes" them favors. These being the same citizens who ridiculed him for wanting to fly and formed an angry mob against him for having dreams earlier in the episode.
Happens to Zuko in a season 2 episode of Avatar: The Last Airbender when a village he saves from corrupt guards instantly turns on him because he was a Firebender.note And not just any Firebender. Prince Zuko, son of Fire Lord Ozai.
Three years earlier, when he spoke out against sacrificing newly recruited soldiers, Zuko got burned and banished for it.
Ironically, in the final episode, Zuko actually thanked his father for it, since it led to his eventual Heel–Face Turn. Ozai likely wished he killed Zuko when he had the chance.
And Haru in season 1, who saved an old guy from a cave using Earthbending, but he turned Haru in to the Fire Nation soldiers.
On The Simpsons, Homer's mom became a runaway outlaw once she helped Mr. Burns after a bunch of hippies walked all over him. Even the producers lampshaded this in the commentary by saying that "Never act in kindness" was the moral.
Frank Grimes saves Homer from drinking a vial of acid, but smashes it against a wall. Burns chews out Grimes for wasting his precious acid and damaging the wall(Though who keeps acid in the dining area?), and even worse, had Frank not saved Homer, Homer might have died.
Also, Ned Flanders attempted to be kind by allowing two female college students to stay while they sleep and work on their studies. How do they repay him? By using the room he rented out to them as a studio for a softcore video site, sexy slumber party. Similarly in the same episode, Flanders attempts to be a good neighbor to his town and to Homer, but his attempts at good deeds are repaid by Homer leaking the video to the whole town, as well as the town cheering on the girls when Ned evicts them, and mocking him behind their backs.
And speaking of Ned Flanders, there's his epic"Reason You Suck" Speech to all of Springfield... except this was after the townspeople had selflessly tried to help rebuild his house. It ended in failure, but they did try, which is lampshaded and derided in the speech itself by Ned.
Bart, as the Shadow Knight, decides to do a good deed and sacrifice two-thirds of his life to resurrect an elf, Marge, although Marge tends to Bart, the same can't be said for the rest of the characters, deciding that his action meant he was easy pickings, and decided to take advantage of his weakened state by brutally slaughtering him. While Bart lost interest on the game anyway, Marge decided to avenge him.
When Homer became smart, he sent a safety report to the Nuclear Regulatory Commission. This led to all the SNPP workers losing their jobs.
During the episode about Jessica Lovejoy, Bart realized she's even more mischievous than he is, after he witnessed her steal the money out of the church collection plate. After he refused to go along with it, she leaves right when the members of the church noticed Bart with the empty collection plate. If not for Lisa's determination to defend her brother, Bart would have been run out of Springfield.
During a Treehouse of Horror, there was a story where Lisa helped a dolphin to escape back to sea. Said dolphin eventually lead other dolphins in taking the surface away from mankind. (They claim they used to live at the surface before being ran out of it by humans) Also, when Lisa noticed a dolphin with a nose stuck at a can ring, she helped it and it bit her hand hard. Lisa almost snaps and curses at the little bastard before Homer sucker punches it.
In The Old Man and the Lisa, Lisa decides to help Mr. Burns after he goes broke on the advice of yes men. Lisa encourages him to become an honest business man and help people by starting a recycling company. But Burns' morality is so twisted, he gets the idea to help people by recycling sea animals into a slurry, to Lisa's utter horror.
Homer: Well Lisa, you've learned your lesson. Never help anyone.
Dib from Invader Zim suffers this constantly. Perhaps most obvious in "Room With a Moose," where the kids mock, wedgy and ostracize him as he tries to warn them about Zim, and then has to use their cruel treatment of him to save their lives. He even considered dooming them despite knowing he'd doom himself as well.
Most of the time, when Disney's Aladdin does a good deed, it turns out okay. However, in "The Citadel", the introductory episode for Knight of CerebusEvil Sorcerer Mozenrath, when Aladdin tries to save a woman and her baby from a monster, they're actually illusions designed to lure Aladdin in so that Mozenrath can try to talk him into capturing another monster. Aladdin refuses, because Mozenrath is Obviously Evil, but then gets sent to Mozenrath's castle anyway. He finally catches the creature, and then decides to do a good deed for it, letting it back into its own world rather than leaving it as a slave to Mozenrath. Essentially, good deeds were in this case punished with the bitter enmity of the series' most powerful villain.
In another episode, thanks to Iago getting a bump on the head, he experienced an uncharacteristic amount of selflessness and charitability by giving away a lot of things, including Genie's lamp. Unfortunately, this characteristic ended up causing more harm than good not only to him, but to everyone near him as well.
Batman always follows through with one rule when dealing with the Joker, sometimes even saving the latter. Come Batman Beyond: Return of the Joker, and the flashback that ensued, Batman most likely will wish he hadn't followed that rule knowing that Batman was in a way responsible for the Joker's most horrific (as well as final) act.
In the Tom and Jerry cartoon "Buddies Thicker than Water", Tom is out in the snow and begs Jerry to help him. Jerry lets Tom into the penthouse apartment he lives in, warms Tom up, and gives him a hot meal. When the owner returns home and attempts to throw Tom out, he ingratiates himself to her by grabbing Jerry and throwing him out in the snow. Of course, this gives Jerry the justification he needs to scare Tom out of the house again and then ignore a second plea for help at the end of the cartoon.
Granted, this was also recycled with the roles reversed in "Snowbody Loves Me". After a frozen Jerry knocks on Tom's door, Tom opens it, after which Jerry sneaks in and locks Tom out in the cold. Similarly an indignant Tom manages to get back in and kick Jerry out, though suffers a Jerkass Realization and lets him back in, this time with more upbeat results.
X-Men: Evolution has the end of season 2: The Sentinel is released, and by sticking around to fight it, the mutants are forced to reveal themselves, causing mass witch hunting and prejudice against them, even after they prove that they weren't responsible for the Sentinel and were the good guys there. Then, as the end of the series proves, the same thing happens when they defeat Apocalypse, and it's revealed that mutant hatred will continue, more, and more powerful, sentinels will be built and used, one of their closest allies will be consumed by darkness, and at least two of them will be noticibly missing in the future line up. Hey, at least Magneto will become good and the Brotherhood will join SHIELD, but since it was SHIELD who were placed in charge of Sentinel production in the present, that might not be a good thing.
In the Popeye cartoon "A Dream Walking", Popeye saves Olive from sleepwalking at a construction site and brings her back to her bedroom. However, when she wakes up, she thinks Popeye is being a Peeping Tom and throws stuff at him.
In "Little Swee'pea", Popeye saves Swee'pea from the zoo animals and bring him home safely. Popeye decides to entertain him with a toy monkey, which scares him, causing Olive to think he's scaring Swee'Pea and promptly cleans Popeye's clock.
"No ifs, ands or maybes, I'll never has babies/I'm Popeye the Sailor Man!" (toot-toot)
American Dad! had one episode where Stan is ordered by the higher ups of the CIA that his boss, Avery, has dementia and is to be escorted to a deserted location so that the CIA can wipe Avery's memory, making him a vegetable. Stan decides to go against orders and keep Avery away from the CIA, even though Avery's behavior becomes more nonsensical and he eventually steals a nuclear powered submarine. Stan refused to believe Avery's brain was turning to mush, but after a while, Stan comes terms over Avery's condition and shoots him in the back of the head. It turns out that a mind scrambling chip was shot instead and it was planted there by the CIA themselves for reasons unknown. Instead of thanking Stan for saving his life and sanity, Avery punishes Stan with a demotion because he didn't follow orders.
The Fairly OddParents: Timmy Turner seems to run into this trope a lot. It's most noticeable on the Christmas specials. He is usually in universe and by fans called out on his selfishness and unwillingness to share. However, in the movie A Fairly Odd Christmas as well as Merry Wishmas, Timmy is condemned for being generous because he's "muscling in" on Santa Claus' territory.
It's pretty common for people to find the titular Kevin Spencer and choose to look past his violence and theft and try to help him get on the right track. Because of thenature of this show, Kevin abuses their kindness and mistreats and steals from them. One episode had him build a friendship with the Widow Coulson, and even though he grew to care for her, he stole her medication.
In "The Nice Guy", Wander's kindness again backfires when his desire to be nice and helpful complicates a simple attempt to buy Sylvia a bottle of her favorite soda. He even ends up giving the last bottle of Thunder Blazz to a little girl... who ends up giving it to Sylvia herself.
Subverted in Total Drama Presents the Ridonculous Race. In the Vietnam challenge, the ridiculously-niceSurfer Dudes allows the Best Friends to reach the Chill Zone first, causing them to come in last and get eliminated. However, a few episodes later the Best Friends have to quit due to Devin's injury; when asked to pick a losing team to replace them in the race, they naturally choose to repay the Surfer Dudes. The Surfer Dudes wind up winning the race in one of the two canon endings.