Soap works because each soap ion has two very different regions: a water-friendly ionic head and a long hydrocarbon tail that prefers oily environments. That molecular split lets water carry away grease it would otherwise poorly wet or disperse.
Water and grease do not mix well. Soap helps because each surfactant molecule has one part that interacts well with water and another that prefers oily material.
Surfactant molecules collect at the boundary between water and grease. Their water-avoiding tails can associate with oily material while their water-friendly heads remain in contact with the water.
With agitation, grease can break into tiny droplets surrounded by surfactant molecules. These structures help keep oily material dispersed in the wash water instead of immediately sticking back to the surface.
Soap also lowers surface tension, allowing water to wet a surface more effectively. Real detergents often combine several surfactants with builders, enzymes or other ingredients for specific kinds of dirt.
Hydrocarbon tails embed in oily material while charged heads remain in water. Agitation breaks a large greasy patch into smaller droplets whose surfaces can be covered by surfactant.
Micelles are part of the story
Above suitable concentrations, surfactant molecules can assemble into micelles. Greasy molecules may be solubilized within these aggregates, but cleaning also involves adsorption at surfaces and emulsion droplets.
Hard water changes performance
Calcium and magnesium ions can form poorly soluble salts with ordinary soap anions. The resulting scum removes surfactant from solution, which is one reason synthetic detergents are formulated differently.
Worked example
Why does plain water struggle with a greasy pan?
Nonpolar grease interacts poorly with polar water, so water alone does not readily disperse and carry it away.
Common traps to avoid
Soap does not make grease chemically disappear.
Micelles are not rigid capsules with a fixed number of molecules.