Some things just don' t mix. Add oil to water and no matter how much you stir, shake or swirl, it will remain separate. Add soap or detergent and as if by magic something new happens.
Water molecules, made up of two parts Hydrogen and one part Oxygen (H2O) have a strong bond. They cling together and are attracted to each other. This can be seen by the surface tension of water. This tension makes it difficult to penetrate and small insects can walk on its surface.
Oil molecules have a weaker bond and a lower surface tension. When mixed with water they cannot break into the water molecules but instead group together. To become stable and release the minimum amount of energy the oil and water need to increase their surface area and lower their surface tension. When oil and water is left to settle, all the smaller droplets gather into one single layer of oil on the water.
Sciencing Video Vault
Soap is a "surfactant" which means some of the properties in the soap molecule are the same as water and some the same as oil. The natural place for the soap to sit is between the two, making a bridge between them. This breaks the oil and water molecules into smaller and smaller groups and they appear to have mixed.