Your skin has a natural protective layer of oil that keeps it from drying out, and keep it flexible. If there are bacteria on top of this layer of natural oil, washing with soap will remove both the oil and the bacteria that sits on top.
Soap can also kill bacteria, by opening holes in the bacterial membrane, which is made of surfactants itself, like soap is. The surfactants in the bacterial cell wall are in two layers, with all of the oil loving ends of the molecules facing inwards between the two layers. Adding soap and scrubbing allows the molecules in the two layers to turn inside-out, and this allows the bacteria to leak, and soap to get inside, where it can harm the bacterium’s enzymes that it needs to live.
Many bacteria adhere to surfaces by creating what is called a biofilm. This is a film of polymers that act as a glue or slime and hold the bacteria together, and help them stick to a surface.
Soap can interfere with biofilms in several ways. It can attach to the molecules that make up the slime, and allow it to be washed away. It can disrupt the attachment between the biofilm and the surface, or it can interfere with the attachment of the bacteria to the film.
Once bacteria have been scrubbed off the skin, the soap attaches to the walls of the bacteria and prevent them from attaching to the skin or each other. They then wash down the drain with the rinse water.
Some hand soaps also contain anti-bacterial chemicals such as triclosan or hexachlorophene, that kill bacteria through other mechanisms. The combination of soap and anti-bacterial agents is better than either one alone.