Hats were once an integral part of day to day clothing, as much as trousers. No self respecting gentleman would go out into the street without wearing a hat.
The saying "I'll eat my hat" is just an expression that is used to show that you are absolutely sure of what you are saying, and you are so sure that there is no chance of being wrong that you will eat your hat (and go hatless) if proven wrong. I don't think that anyone actually ever ate their hat.