It's a useful quantity because the variety of units allow for the speaker to drop the numerical portion of a quantity of a substance.
Meaning, the phrase "gallon of milk" is ever so slightly easier to say/verbalize than "four liters of milk." Or alternatively, "half gallon of milk" vs "two liters of milk."
Likewise: "pint of beer" vs. "<half liter/5 deciliters> of beer", "1 cup of flour" vs. "<quarter liter/250 mL/25 centiliters/120 grams> of flour".
But you're not saying "four litres of milk" that often. You're saying "a carton of milk" and typically the people understand that that is a litre or 1.5l or whatever it is you usually buy. As for beer, again, where I drink it's typically either unspecified or a "small", being 25cl and 15cl respectively (this being a nerdy craft beer bar where smaller sizes are preferred.) If you do want to say the size, you can just say 25 or 15, no one is going to think you want 15 litres because that'd be weird.