why does saturn have smaller density than earth and mars which is smaller than saturn?

Density is how tightly packed the matter is. It has nothing to do with the size of the body.

Saturn is a gas giant. Earth and Mars are rocky planets. Generally, rock is denser than gas.