Density is defined as the ratio of the amount of matter (mass) to volume. See the densities of some common solid elements represented as points, whose size is proportional to the mass contained in each volume. The amount of matter represented by the dot is supposed to be distributed homogeneously in the volume. By increasing subdivisions, you get the same mass, but distributed proportionally in the volume of each cube. Gases are not considered here because their densities are very small compared with solids.