This term has generated at least two plausible speculations about its origin.
Contrary to the first impression at hearing or reading the term, a ten-gallon hat does not hold ten gallons. Such a hat would best befit a clown, not a cowboy.
No, “ten-gallon” does not refer to the internal volume of the hat.
Instead, there are at least two possible origins to the term.
Both origins are from Spanish, both origins relate to distinguishing this type of hat from a sombrero, and both origins represent the effect of an outsider’s perspective in hearing a foreign-language term and corrupting it into something in the listener’s native tongue (in this case, English).
The first possible origin is based on the idea that a “ten-gallon hat” is for the upper classes, in contrast to the lowly sombrero for the lower classes. Upper-class cowboys were considered to be more gallant than commoners. The phrase “so gallant” in English is expressed as “tan galán” in Spanish.
If you “squint your ears” at the sound of “tan galán”, you easily could get “ten gallon” in English.
The second possible origin is based on the fact that a vaquero — Spanish for “cowboy” — would be awarded for cowboy expertise a narrow band, often braided, around the crown of the hat. Ten of these narrow bands on one hat represented the ultimate in cowboy skills. The Spanish word “galón” refers to such a band; “galones” is the plural of this word.
A non-Spanish-speaking, native-English-speaking listener could easily misinterpret “galones” into “gallons”.
The other meaning of “galón” is, in fact, “gallon”, so a native-English speaker with a knowledge of this primary definition of “galón” could easily interpret “diez galones” as “ten gallons” instead of “ten bands”.