You're playing with a sharp pocket knife when it slips from your hand and lands point down in your friend's foot. You didn't mean it. You were just playing around, but somehow that doesn't ease the pain or staunch the blood.
Why are words different? Why do people assume that their intentions are relevant when their words cause pain or offense? If the pen is mightier than the sword aren't words something to be used with care?
There is, and has been for some time, a lot of backlash against what's wrongly labeled being politically correct, and I will acknowledge it might seem there's a mine field of offense just waiting to explode at any step. That's a different conversation. I'm talking about direct personal insult (though I course there is overlap).
The remedy when your tongue slips instead of your knife is not 'I was just joking' - which places blame for the offense on the offended party's lack of humour. The remedy is a simple formula each one of is should have learned in childhood.
I am sorry I X
I realize it was wrong because Y
I will do Z to make sure it doesn't happen again.
That is the simple and dying art of apology. You will notice the formula does not include spots for either blame or explanation. In business we call it crisis communications. In the rest of life I call it's called taking responsibility for yourself.