Note: The phrase origins, or history of particular idioms can be difficult to trace down, so finding the precise time a saying came into existance is no walk in the park. What you will usually find on this site are moments in history where an expression started to be used on a widely-known basis.
For instance, some sayings can be spotted in an old newspapers from several decades ago, but think about that for a second. If an idiom is being used in a newspaper, then everybody already knows about it! What does that mean? Well, if the saying is commonly known already, then that's not where its origins are, it has to be older than that.
On that note, what's standard here is finding an early written form of the phrase, usually coming from a book, poem, play, etc., and then based on that, it gives you an idea on how old an expression could be, but not necessarily how old the idiom really is. It's an estimate.
knowyourphrase.com - Meanings and Origins of Phrases
Common Phrase Origins and Meanings>E-Letter Idioms
Speaking in a literal sense, would you really want to eat a hat? I wouldn't think so, considering they are made from materials such as cotton, linen, and leather; none of which sound particularly appetizing. Moreover, consuming a hat could be potentially dangerous, and it probably doesn't taste very good either.
Leather, for instance, goes through a tanning process where it's treated with various chemicals that help strengthen it. While the chemicals do their job of increasing the leather's durability, eating it may possibly cause health issues. Plus, the amount of chewing required to even swallow the leather would probably hurt your jaw. In short, just leave the thing on your head.
Nobody really wants to eat their hat. That's why this expression is only said when a person is feeling extremely confident about something.
This phrase makes an early appearance in several newspapers from the 19th century, one of them being the Iowa South West from the city of Bedford, 1876:
"If you are not Joe Kirby," he said, I will eat my hat-I mean, of course-"
"Come, this is trifling. I say that you mistook me for some one else. What makes you think me Joe Kirby?"
"Because you are."
Having confidence in a specific outcome; being almost sure about something.
When a person makes a strong assumption, they may use popular idioms and phrases like this one to describe their feelings of near cerainty.
* Susan takes excellent care of her teeth, so there's no need for her to worry about going to the dentist. Why, if she has a cavity, then I'll eat my hat!
* A few of my friends said they'll eat their hats if I manage to beat Richard in a race across the park. I guess they have little confidence in my running speed.