Soil behaves as a filter. Some soils are better filters than others. Fine particle clay soils are the most efficient at removing microbes while course gravel soils are less efficient. Sewage treatment is also performed in several steps that closely parallel water purification procedures. Primary involves collecting the sewage at the treatment plant and the removal of solids by sedimentation and precipitation.
Secondary treatment involves reducing the concentration of the dissolved chemicals.
This is a microbiological process. There is a term in ecology called the BOD which are the initials for biochemical oxygen demand, and is a measure of the oxygen that would be required for microbes to metabolize the dissolved organics in the water. If secondary treatment is incomplete, a high concentration of organics will be in the effluent and when microbes in the water way metabolize the organics they will use up the oxygen, causing the water way to go anaerobic, and this will kill the vertebrate and invertebrate life. Tertiary treatment involves elimination of the microbes and reduction in concentration of the remaining chemicals. Then the treated water is returned to the environment.