Biography
For a very long time, TV writers seemed to think that one of the universal signs of mental illness was a total inability to perceive one's self as acting oddly. It's tempting to have a mentally ill person utter such classic Mad Scientist lines as, "They Called Me Mad!, but I'm not mad, they're the ones that are mad!" And certainly, the near sociopathically quirky characters you find on the average Sitcom seem to think themselves perfectly ordinary, and in Real Life, some people afflicted by mental illnesses don't realise there's anything wrong with them.
Fortunately, this is not always the case. Few characters can be more fun than the Self-Aware Loon. He's crazy and he knows it. And he's making the best of it. Trying to dissuade them from following their crazy, broken logic by pointing out their insanity will never, ever work. To them, it will be the sincerest form of flattery.
They may be a Talkative Loon most of the time, but they have their lucid moments, and may even consider their episodes to be a welcome respite from normalcy.
Consequentially, they often get to say clever lines like, "Well, I think it's a good idea, but then, I'm crazy," "I'm crazy, but I'm not stupid," "I may be insane, but you're crazy" or "Oh yes, I'm insane. And you're stuck here with me."
Mostly characters who have become unhinged by an exceptional ordeal; rarely results from an organic disorder. Often a facet of the Waif Prophet or the Rabid Cop; and frequently a major character component of the Shell-Shocked Veteran and Special Forces military types.
Usually a fun character, and a little cartoonish, though it can also be played tragically (this is how it usually goes when The Mad Hatter's illness is organic in origin) as a character is overcome by the knowledge that they are losing their mind and are powerless to stop it. Can also be played for horror, if the affliction goes beyond "quirky", as such characters can know exactly what they are doing, and just not care.
This trope could be considered insensitive to viewers with actual mental illnesses. On the other hand, perhaps they can take some solace in a depiction of mild mental illness as something that can be coped with. And as with issues like ethnicity and disability, when characters have a sense of humor about their condition, it may not come off as too insensitive.
Archetype is named for the character from Alice's Adventures in Wonderland, who, like most of Wonderland's residents, knows exactly how crazy he is, and has decided to just sit back and enjoy it. Carroll's Mad Hatter is in turn a reference to the tendency of Victorian era hatters to go mad; "as mad as a hatter" was even a common phrase at the time. The actual cause of the phenomenon was the presence of mercury within the solution used by hatters to shape and form the felt – the hatter would inhale and ingest trace amounts of mercury during his work and eventually suffer from mercury poisoning, leading to dementia and death. Contrary to popular belief, Carroll never actually refers to the character as "the Mad Hatter" in the book; he is simply called "the Hatter".
See also the Reluctant Psycho, who has mental problems. Compare Obfuscating Insanity, when the character pretends to be mad. Related in variable ways to The Wonka.