Theory:

Soap and detergent are water-soluble compounds, i.e. they dissolve in water quickly.
The saponification process between the sodium or potassium salts with the fatty acids makes up soaps for cleansing purposes.
Detergents are also called surfactants as they reduce water's surface tension (resistance to external forces to penetrate).
Surface tension: This property is based on cohesive forces that exist between the liquid molecules. The molecules present in the liquid undergo a net inwards force with no force acting above the surface—causing the surface molecules to contract and resist breaking.
This is why objects float on the surface of water, such as mosquito walking and paperclips floating on the water surface.
 
BeFunky-collage (18).jpg
Surface tension
Hydrophilic group (head) - water-loving

Hydrophobic group (tail) - water repellent
shutterstock_1681450900_new.jpg
The hydrophilic and hydrophobic end
 
The hydrophilic and hydrophobic groups in the soap molecules react with the water molecules and cleanse the dirt away. The dirt mostly contains oil which is insoluble in water.
 
The long-chain carbons present in the soap makes the hydrophobic group which attracts the oil present in the dirt, and the sodium molecule acts as the hydrophilic group, which is water-loving. This formation is known as micelles.
 
shutterstock_1502937632.jpg
Cleansing action
 
In this image, we can see the head and the tail, which cleanses the dirt away. These micelles act in cleaning the dirt from the fabric.
 
shutterstock_688765441.jpg
\(3d\) image of the micelles
 
This image shows the action of micelles cleaning the dirt from the scalp and hair. Similarly, this type of cleansing action takes place in shampoo, floor cleaners, hand wash etc.