I very often see なんてね or some similar phrase being translated to "Just kidding"? but why does it mean this and how does the grammar behind it work?
なんて is an informal word that is used after some phrase and implies it is not important.
Basically when you're kind of ignoring the importance of, or even slightly putting down, the topic of the sentence. 愛なんか要らない。(I don't need love!)
So when なんて is used like a standalone interjection, it means you said the previous sentence not seriously.
ね is a sentence-end particle and thus optional. You can say なんて! ("kidding!") without largely changing the meaning. なんてな is the same (sounds a bit more masculine).
The verb 言う is omitted after なんて. So you can translate it "saying (something) like that", or virtually as a subjunctive: "(as if) it be/were like that". That's why it comes to have "I'm kidding" sense.
A synonymous expression is なんちゃって (< なんて言っちゃって). This one also works as a slangy adjective "pretend", as in なんちゃって家族 "a pretend family".
I'd rather you were dead, just kidding.
『あんたは、死んだ方がいいよ』(Once you said it cleary, then) って本気で言ったと思う？本気じゃないよ、冗談だよ。
"I'd rather you were dead. (Once you said it cleary, then) Can I say it in earnest? NOWAY! I'm just saying it in fun."
→ I'd rather you were dead, just kidding.