Biography
While in Real Life there is rarely a direct and easily traced cause-and-effect relationship between Bob's actions and their subsequent reward or punishment, in fiction the connection is usually a lot more... express. Did Bob help an old lady across the street? Several chapters later, she'll turn out to be an elite ex-commando who will gladly help him storm the Big Bad's castle. Did the Big Bad kick the little dog just because it was barking at him? The dog will sniff him out and lead the heroes right to his Supervillain Lair.
The Golden Rule states, Do unto others as you would have them do unto you, but in fiction, morality operates more on Newton's Third Law — Every action results in an equal and opposite reaction. Abuse others, and the cosmos will heap that same abuse on you. Accordingly, every notable act of a fictional character will yield its due return before the end of the story; every deed, good or bad, will be repaid with the accuracy of a laser-guided missile. Whether its payload is sunshine and puppies (see Earn Your Happy Ending) or painful irony depends on whether Bob was a saint or a bastard.
This is a common trope for works containing An Aesop about morality. But if taken too far, the story will turn unbearably anvilicious: be polite to strangers, never kick puppies, et cetera, or the universe itself will make your life a living hell. It also undermines the standard "do good for goodness' sake" lesson, since Bob never has to suffer for doing the right thing or accept virtue as its own reward — in Fictionland he will always get repaid. That being said, the negative consequences tend to fall more directly than the positive; the villain's own deeds will be the ultimate cause of his downfall, while the hero's merits win him some much-needed assistance but do not provide a Deus ex Machina that solves all his problems for him.
On the good side of the karma coin:
Helping out the Character Witness gets you an advocate.
Aiding a wild beast befriends Androcles' Lion.
Helping a stranger will put you in the good books of an Angel Unaware or King Incognito.
Giving the scavenger kid a meal gets you a Sidekick.
In general, these good actions net heroes a Karmic Jackpot and the bad guy a reprieve.
On the bad side of the karma coin:
Dismissing the sorceress in beggar's robes gets you turned into a monster.
Mocking Bugs Bunny will land an anvil on your head.
Accusing someone of stealing your wallet gets him to exact what you accused right on you.
Attempting to use a power for your own gain gets you defeated by that exact power.
Demeaning the secretary gets him to help the heroes.
Simply put, bad deeds earn heroes (at the very least) a swift lesson in better behavior, while villains suffer all sorts of unpleasant consequences.
See also Pay Evil unto Evil, Sweet and Sour Grapes, and Sexual Karma, especially Karmic Rape. Ironic Hell is the afterlife version of this. Contrast Karma Houdini and Karma Houdini Warranty. For karma punishing a hero for their mistakes, see Tragic Mistake. Also contrast with "No Good Deed Goes Unpunished", which is a corrupt form of this trope; as well as Can't Get Away with Nuthin', where the slightest misdeed committed by the hero results in Disproportionate Retribution. If the character is a jerkass and the karma isn't enough to make them learn, then it's a Karmic Butt-Monkey.
When you help someone but receive punishment rather than reward, you might be looking at The Farmer and the Viper.
See also: Hoist by His Own Petard, when a villain gets killed by their own weapon, or The Dog Bites Back, when they're killed by an abused lackey.
For sake of trope differentiation, examples should be limited to bad karma, heroic or villainous, and when an opponent's "good karma" combines to double-wham the antagonist.
Since in Real Life, whether a bad thing that happened to someone had been karma or not is inherently controversial and subjective, No Real Life Examples, Please!
This trope is by its nature Spoileriffic; spoilers will be unmarked.