That bile emulsifies the fat, essentially making fat organize into small " micelles" , which are tiny bubbles of mixed lipids and bile acids, rather than clumping together, and making them easier to absorb.
These surfactants have their hydrophilic head and their hydrophobic tails, and so they form these micelles around the dirt, which is what grabs onto dirt and oil, and helps it to remove it from the hair and the scalp.