Soap removes an oil spot through a process called emulsification. When soap is mixed with water, it creates molecules with a hydrophilic (water-attracting) head and a hydrophobic (water-repelling) tail. The hydrophobic tails are attracted to the oil in the stain while the hydrophilic heads are attracted to water.
As you apply soap to the oily area, the soap molecules surround the oil particles. The hydrophobic tails latch onto the oil, and, as you agitate the mixture (for example, by scrubbing or rubbing), the soap molecules form structures called micelles. In these micelles, the tails trap the oil in the center while the heads remain outside, interacting with water.
When you rinse the area with water, those micelles are washed away, taking the oil with them. This is why soap is effective in removing oil stains — it allows the oil to mix with water so that it can be rinsed away easily.