When looking at energy density of batteries it is often expressed as Wh/L. For instance, Wikipedia says Lithium Ion batteries have a density of 250–693 W·h/L. Liters is supposed to express the volume but the volume depends on the density of the substance. So liters of what? Water?
Volume is volume. A (large) battery that is a cube 10 cm on a side has a volume of 1 liter regardless of what it is made of, or what density it has.
I think you are getting confused by the word "density".
The actual use of "density" refers to any quantity measured relative to a unit volume. What we often call "density" actually means mass density, or mass per unit volume. That is likely why you are associating mass with density.
When they say "energy density" though, they are referring to energy per unit volume; and it isn't really related to mass density; besides that they are both quantities expressed per unit volume.
A liter is simply a unit of volume equal to 1000 cm$^3$. It could be a volume of anything (air, water, a solid). Technology is trying to pack more energy into a smaller volume of a battery to save space.
Hope this helps.