A liquid has no definite shape and assumes the shape of whatever container it is, solids have their own shape
Because of this when you fill a barrel (or any container for that matter) with a liquid, it will perfectly utilise all available space without any losses. When filling the same container with solids, there will not only be empty spaces between the items and the walls of the container but also between the items themselves, this way you're losing some of the theoretical capacity. Imagine a barrel filled with potatoes, they will not perfectly fit against each other, some space will be wasted in the barrel. I believe this is the reason for the differences in capacity, they are taking into account that packing solids will be more wasteful than liquids. Exactly how much space you waste depends on what sort of solid you're filling the bucket with (e.g. potatoes will be more wasteful than grains of sand) but you will never get the sort of perfect fit that you can achieve with a liquid.
As to the difference in case of the bucket, it could indeed be due to the fact that you can fill it with a heap on top if you put something solid in, which you cannot do with a liquid but I think that this is more for convenience, 3 gallons (imperial) is about 0.48 cubic feet, this is very close to 0.5, which is easier to work with than, say 0.4 and unlikely to make a difference in the context of a game.
The volume lost in case of the barrel is around 25%, which is consistent with the densest sphere packing in 3 dimensions, the math behind this can be found here for those who are interested: https://mathworld.wolfram.com/SpherePacking.html.
This does assume that you're using items spherical or close to spherical in shape but I think this is a fair generalisation given that D&D is a game, not a physics simulator.