Soap are molecules in which the two ends have differing properties. One is hydrophilic, that is, it interacts with water, while the other end is hydrophobic, that is, it interacts with hydrocarbons. In the clusters of molecules in which the hydrophobic tails are on the surface of the cluster. This formation is called micelle.
Since the oily dirt will be collected in the centre of the micelle. The micelles stay in solution as a colloid and will not come together to precipitate because of ion-ion repulsion. Thus the dirt suspended in the micelles is also easily rinsed away.