Many impurities and dirt are mixed in the water, and most of all the dirt does not dissolve in the water. Soap molecules are a combination of salts such as sodium or potassium. The molecules are of a long chain of salt of fatty acids. So, when the carbon chain is dissolved in oil and the ionic end is dissolved in the water, the soap starts cleansing and trapping the dirt. When this happens, the soap molecules form structures that are called micelles and are used for capturing the oil droplets and then the other end is the ionic faces. This will then form an emulsion in water and help in dissolving the dirt or impurities when the clothes are washed.
The soap molecules have different properties at different ends. The first end is the hydrophilic end which dissolves in the water and is attracted to the water and the second one is the hydrophobic end is dissolved in the hydrocarbons and is repulsive to water. The hydrophobic tail aligns itself along the surface of the water because it is not soluble in the water.