The rock must be exposed at surface. This means uplift and removal of overlying rocks and sediments is required. Once exposed, chemical and/or physical weathering can reduce the rock to smaller loose fragments (sediments). The sediments can be eroded and then transported by a variety of mechanisms.
Sediments are buried beneath other sediments, where pressure compacts the sediments, forcing grains closer together. Mineral cement forms around the grains, binding them to each other and into solid rock.
Rock is buried deeply in the crust and exposed to very high temperatures and pressures. Under those conditions, a new type of rock is formed when minerals undergo physical changes and chemical reactions.