Sediment turns to sedimentary rock through burial, compaction, and the addition of mineral cements.
Earth's crust flexes as a result of plate tectonic and local forces, sometimes as uplift, sometimes as subsidence, and sometimes as either uplift or subsidence along faults. In a sedimentary basin, sedimentary layers accumulate as subsidence happens, usually gradually and slowly, but it can be very rapid to form immense volumes of sedimentary materials. It is common to see sequences of sedimentary layers that are 1000s of meters thick to 50 kilometers and more. The layers on top have undergone only slight burial, but layers down deep, often several hundred million years older than the top layers, lie beneath a thick pile of material. The typical geothermal gradient carries temperatures down that far to what you would typically think of as "boiling" temperatures for water (but, pressure increases with depth also, serving to check the effect of temperature). So, at typical depths near the bottom of a sedimentary sequence, temperatures are at least warm and can be quite hot, but not hot enough to induce significant metamorphism of the rocks.
Sedimentary particles of all types are squeezed closer together as deposits get buried. Water that is buried with sediment, occupying the space between the particles, gets squeezed out in the process. Some water remains as pore fluid in the material as it is buried. Sand and other hard mineral grains will come into more contact and nestle together more. Clay mineral particles, which are minute and have a flat shape, also compact greatly through burial. Other types of sedimentary materials undergo similar changes.
Water usually fills pore spaces, at least partially. Of course, even in surface waters, water isn't all H 2 O, as there are minor amounts of the usual common elements at the Earth's surface, including Ca, Na, K, Fe, Si, O, etc. These common elements form common minerals you are familiar with, growing as tiny crystals lining the walls of pore spaces, sometimes forming only a rim of mineral cement coating the particles, other times growing to fill almost the entire pore space. Two principle cementing minerals are calcite (CaCO 3 ) and silica (or just quartz, SiO 2 ). Iron oxide minerals are also common as mineral cements (You remember hematite and limonite, with the Fe 2 O 3 formula). The growth of mineral cements brings a reduction in the amount of pore space, or porosity, but usually there is at least a few percent of pore space.