I have been telling my sons this since they were 5 years old….
Child says mean or rude or otherwise unacceptable thing
Me: “Not acceptable. That was mean/rude/hurtful. Apologize.”
Child: “I was just joking.”
Me: “Was it funny to both of you?”
Child: “Well, no.”
Me: “Then it wasn’t a joke. You’re making an excuse for being a jerk.”
It’s not that hard.