Shouldn’t it be “Hat on a Cat” instead of "Cat in the Hat"? The hat is sitting on the cat. If it was a cat in a hat, it seems like the cat would be completely in the hat.
Presumably, you are talking about this cat:
If not, that's OK.
Hat on a cat describes a hat being atop a cat, as you say. Cat in the hat can mean what you describe, the cat being inside the hat (e.g. the cat being inside a much larger hat). However, there is a different usage of in here:
If you are dressed in a piece of clothing, you are wearing it.
He was a big man, smartly dressed in a suit and tie.
...three women in black.
In other words, we can use in [article/piece of clothing] to mean that someone or something is wearing the clothing. So we understand that the cat is wearing the hat, like above. This usage of in is common:
- the man in the red shirt
- the girl in the skirt
- the boys in blue* [= the boys wearing blue attire]
- the baby in the skeleton costume
*As @ShadowRanger mentions, the cops are sometimes referred to as the boys in blue, but actually I had the Los Angeles Dodgers and their iconic white and blue uniforms in mind at first (too soon!!). Regardless, this broadly applies to anyone in any color clothing. The context will make the meaning clear.
The other answers do a fine job explaining how the you can use in to describe someone wearing clothing. However, there is another difference between the two alternatives you give that I would like to highlight.
The phrase "cat in the hat" focuses on the cat (who is wearing a hat), while the phrase "the hat on the cat" focuses on the hat (which is being worn by the cat). When using the phrase without the context of a sentence (e.g. as the title of a book) this is a simple matter of which of the two you want to focus on.
However, when using the phrase as part of a sentence, this becomes a lot more relevant. Consider the following two sentences:
The cat in a hat is black
The hat on the cat is black
The first sentence is about a black cat wearing a hat. The second sentence is about a cat wearing a black hat.
You can also use in to mean dressed or attired in something. I would expect this usage came from French.
- the man in the suit
- the woman in the pretty sun dress
- a boy in a bathing suit
- the girl in an orange wig
Also, in the story, there are a series of recursive cats in corresponding hats. A cat's hat in that context is actually the hat belonging to their host cat, which they are in fact positioned entirely within. Not for nothing.
The Cat: Because it's a specific cat having a specific identity and/or personality. If it were about any cat, it would be A Cat.
In: Because he's wearing it. If you are wearing an article of clothing you are dressed in that article of clothing. On a cat means the hat is sitting on top of a cat but the cat isn't wearing it. The cat just happens to be existing underneath the hat. It would not have the same meaning. It must be In because the cat is wearing the hat, not just sitting underneath it.
The Hat: Because the hat is also special. If it were just about a cat that wears any of a number of different hats it would be called The Cat In A Hat. But this book is about a specific cat and a specific hat.