Hydrocarbons are insoluble in water because they are non-polar compounds while water is a polar solvent. By principle, like dissolves like. Nonpolar solvents dissolve nonpolar solutes and polar solvents dissolve polar solutes.
Benzene and chloroform are nonpolar solvents. They will dissolve waxes, grease, and organic fats which are non-polar.
Similarly, water is a polar solvent that will dissolve polar solutes including NaCl, AgNO3, and K2SO4.
The solubility of the compounds in like solvents is because of the type of intermolecular interactions present in them. These interactions originate from the polarity present.
If a molecule is made up of two or more atoms, the polarity of that molecule is the difference between the electronegativity of the constituent atoms.
The below table shows the type of intermolecular interactions within a substance depending on the difference in electronegativities (ΔE.N).
Hydrocarbons have negligible polarity and they have weak intermolecular interactions known as London dispersion forces i.e. Instantaneous dipole-induced dipole interactions.
Whereas, water has dipole-dipole interactions (and hydrogen bonding as well). They cannot interact with each other due to different interactive forces. Therefore, hydrocarbons are insoluble in water.