From a chemical point of view, the secret of soaps and other surfactant detergents is that they reduce the surface tension of the water, thereby enhancing its detergent properties. Molecules of surfactants on the boundary surface are arranged so that hydrophilic groups are directed into the water, and hydrophobic ones are pushed out of it. As a result, the entire surface of the water is covered with a sort of fence of surfactant molecules. Such a water surface has a lower surface tension, which contributes to the rapid and complete wetting of contaminated surfaces.
For those who did not understand, there is a simpler explanation why soap washes: the soap contains caustic soda and natural fat. When soda and fat are combined, a soapy mass is obtained, which contains a great many bubbles with a water shell. It is the bubbles that have enveloping properties that lead to the formation of emulsions of various pollutants and prevent their re-deposition on the surface. In other words, dirt particles stick to the bubbles, and the foam itself under running water is much easier to wash off.