When magma is emplaced at depth or extruded onto the surface (then called lava), it starts to cool and mineral crystals can form.
When rocks get very hot, deep underground, they melt and become magma which is full of tiny parts called ions. As the magma cools down, those parts slow down and stick together to form crystals. And that's how new minerals are born.