A rock changes from one type to another when subjected to certain conditions and the process is known as the rock cycle.
When lava cools down, it solidifies to form igneous rocks or primary rocks while sedimentary rocks are formed when igneous rocks are broken down into small particles, carried to other places, and deposited in layers.
When igneous and sedimentary rocks undergo great heat and pressure, they change to form metamorphic rocks over time. However, metamorphic rocks, under great heat and pressure can further melt to form molten magma. The magma returns back to the magma chamber under the earth’s crust.
This magma again cools down and form igneous rocks. This process leads to the rock cycle.