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. In this case Karma is being unpleasantly harsh.
It is a taunt aimed at people who are supposedly asking for the situation they are in, due to their previous actions.
So the person saying it, considers the one they say 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 they walk straight into a lamp post and break their nose. A spectator who did not find the accident they saw funny, could say "Ain't Karma a bitch?"