The process is called as compaction.
Compaction is the process by which the sediment progressively losses its porosity due to the effect of loading. When the sediment is formed by its own it contains pores. The pore space is usually filled with water. As the sediment is deposited over time the upper layer of sediments pushes the lower layer and due to this reason the sediments deposits and stick together to form solid rock. The pore size of different sedimentary rock is different like mudstone has porosity of more than 60% and sandstone of porosity more than 40%. The porosity is reduced by compaction.