I looked it up on Wikipedia (https://en.wikipedia.org/wiki/Gallon). Seems it all got put into law around the start of the 19th century. The only problem with the civilised and rational metric system is that it was developed by the revolutionary French. Still there were already two different gallons widely used for trade. The US adopted the wine gallon while the British went for the bigger ale gallon. See what a mess you get into making decisions based on national pride .
Expanding on the Wikipedia entry, the English American Colonies used (naturally) English weights and measures. After the War of Independence in 1777 they continued to do so.
So when the British decided to standardise their weights and measures in 1824 to Imperial Measurements the United States of America, being independent, had no cause to change and have thus continued to use old English measures.
The standardisation of the gallon in each country would have been based on custom and practice of the time.
Not much beer would have been imported into the USA as beer needed to be consumed close to its point of consumption because of its short shelf life due to its lower alcoholic (preservative) content. Wine would have been imported into the USA because it had a higher alcoholic content, thus a longer self life and could travel well and improve with age. This was also true of some very strong beers like Guinness Foreign Extra Stout (which also improved with age) and Carlsberg Export although these (and only recently) are now pasteurised. More beer was consumed in UK than wine so that was a natural choice of measure. More wine was imported into the USA, so that was a natural choice.
When UK adopted the metric system many items stayed the same but the stated measurement changed, so a 12oz jar of jam became a 340g jar of jam. Same jar of jam. There are many other examples. Milk is sold as 2.2litres in a 4 pint bottle. People don’t really go out to buy 340g of jam or 2.2 litres of milk.
The same principle applies to shoe sizes which are measured by grains of corn. The measurements differ between UK and USA because different grains were being used. Each system now has a standardised but different grain size.
Much of things in America follow the pre independence old English style. So what we call pavements, they call sidewalks and what we call roads they call pavements. Americans call corn what we call maize. All of which has some logic.
English English is a constantly changing language. American English is much more conservative and continues to use English in its unevolved way including its use of old English spelling (like standardized).
I see the Oxford Concise English Dictionary has changed the definition of Woman.
The world keeps spinning.