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?
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.