I think what you did was a bit immature and should show a side of you that you may want to look at more deeply and reflect on.
This isn't to bash you as it can be hard to judge what is or is not funny especially to others.
What might have seemed funny to you though obviously did not seem funny to your friend.
Some people make jokes about other people, family and friends, and talking behind there backs and say it was just a joke and think its no big deal.
The ironic part is usually its not much of a joke when its done back to you.
What's a joke to you might not be a joke to another, and what's a joke to another might not be a joke to you. This is a lesson of consideration.
Most of us are not mind readers or empaths where we know everything that is going in another persons mind or in there life.
I think if your friend dwells on negative stuff you should think of more constructive ways to support him.
But i will say again this isn't to bash you. And i don't know your friend. So its hard for me to really say any of this without a grain of salt.
Id imagine your friend is similar to you. Since i know that if i had any friends they would be like me. And i wouldn't let someone in my life who isn't there in my best interest.
One thing that i learned as i got older, was all the baggage i acquired from people, friends, family, society, music, movies, culture, and the world.
As i got older i choose the path less walked on. The hard path is to look deeply at oneself and may require some sacrifice.
Ignorance is bliss. Its easy to look away and ignore things then to face it head on.
Just remember growth comes from the challenged we overcome.