In a layered shot, the bottom layer is typically denser and thicker (in science terms, it has a higher specific gravity) than the layer on top. Liqueurs are heavier than water or other liquids because they have sugar dissolved in them. Cream is even lighter than water or alcohol because of the fat content! This makes it much lighter than the sugary liqueur, so it easily floats on top, especially if you whip some air into it.