VOLCANOES are just a natural way that the Earth and other planets have for cooling off and releasing internal heat and pressure.
Volcanoes erupt because of density and pressure. The lower density of the magma relative to the surrounding rocks causes it to rise (like air bubbles in syrup). It will rise to the surface or to a depth that is determined by the density of the magma and the weight of the rocks above it. As the magma rises, bubbles start to form from the gas dissolved in the magma. The gas bubbles exert tremendous pressure. This pressure helps to bring the magma to the surface and forces it in the air, sometimes to great heights.
It is just like the bubbles of gas in a bottle of soda. Before you open the soda you don’t see many bubbles because the pressure in the bottle keeps the gas dissolved in the soda. When you open the bottle the pressure is released and the gas bubbles leave the soda. If you shake up the bottle first, the soda gets pushed out by the bubbles of gas as they rush out.