The most common way to change the density of compounds is to change their temperature. Heating a compound activates the molecules so they spread apart, making the compound less dense. When you heat water, it expands, and when you cool the compound down again, it increases the density.
When a lava lamp is turned off and you look inside, you’ll find a solid waxy compound on the bottom of the globe. This solid compound is only a slightly denser than the surrounding liquid compound. When you turn on the light at the base of the globe the solid quickly turns into a liquid and expands, giving it a lower density than the surrounding liquid. Because this warm solid is now slightly less dense than the surrounding liquid it rises to the top of the globe.
The warm solid is now farther away from the heat source, so as it cools slightly it becomes more dense than the surrounding liquid, but is will not cool down enough to change back into a solid. This warm solid will sink to the bottom of the globe, where it will heat up enough to rise again.
Even though this is a pretty simple idea, it is actually fairly complicated to balance all of the elements, the compounds, the heat source and the size of the globe so that the compounds are constantly moving around.