After a long time, water is squeezed out of the sediment. Minerals like calcite from hard water fill in the spaces and cement them together, turning the sediment to a sedimentary rock. This may also happen to the fossils inside.