Without specifics this can be a hard one to answer. There are a ton of things that are okay when one person does them, but not okay when someone else does them because of the relationship.
For example, lets say I'm at work and I do something silly/stupid but not harmful. I can say "Oh, I'm such an idiot!" My work-BFF could also say, "Ha, you are such an idiot!". But if my boss or another random co-worker who I don't really interact with were to say "Ha, you are such an idiot!" I would find it inappropriate and possibly hurtful and offensive depending on the tone.
Because I'm allowed to tease myself. My friends can tease me. But if we don't have a teasing relationship, then its more mean spirited.
It's also possible that something is okay going one direction, but not okay going the other direction. Like it would be acceptable for my boss to address me about my wardrobe as it pertained to establishing a dress code, because he gets to set the dress code. But it wouldn't be okay for me to address him about his wardrobe (barring extreme circumstances), because he gets to set the dress code.
And finally, sometimes things are similar, but not the same. Different tones, slight differences in phrasings, substituting apple for orange - these things can often make a big difference on if something is okay or offensive.
So the first step is being really honest with yourself about whether it's really the same or not. And also about whether it is/could be offensive.
ETA: saw your update. I think saying "what the hell" is a great example of something that can be okay or not okay depending on the circumstances. Said angrily to someone vs. said generally at the cosmos. Said in front of young children vs just adults. Now, if all things are equal it's also a small enough thing that you could probably just shrug it off. Or look confused and say "but Grandma, I learned it from you!"