An exclamation, meaning: Serves you (him) right! I told you (him) so!
Expression said to children or adults if a warning has been ignored. But adults may resent it and retaliate.
Serves you right! That’s why you were told beforehand. Because you didn’t listen, that’s why it is like that.