Scientists base this on how they were formed. Igneous rocks are formed by cooling of magma, Sedimentary rocks are formed by accumulation of dirt over many years, and Metamorphic rocks are formed when igneous rocks or Sedimentary rocks undergo extreme pressure and temperature often below the surface of the earth.
Hope this helps you<3