Also used as the rhetorical question
Ain't karma a bitch?
- What goes around, comes around
- Getting his just desserts
- He had it coming
and strongly related to
It is likely a mix of having bad Karma and the idiom Payback's a bitch, where Payback is performed by someone wronged by the now punished person, but Karma just happened to the person for some seemingly righteous reason not necessarily related to a person or physical entity.
The bitch part is personifying the concept Karma, which is claimed to have doled out the resulting punishment.
It is a taunt aimed at a person who is supposedly asking for the situation he is in, due to his previous actions.
So the person saying it, considers the one he says it to or about deserves to be punished because of something they did.
For example: someone is so busy pointing and laughing at a person who had an accident, that he walks straight into a lamp post and breaks his nose. His friend who did not find the accident they saw funny, could say "Ain't Karma a bitch?"
Here is a short movie giving a good idea: Karma's A Bitch from Justin Tan (Likely NSFW for some)