So soil quits filtering when it detects groundwater?
Water seeps into and through the soil. If the water is constantly contaminated eventually the contaminates will build up throughout the soil. It becomes a vicious cycle.
Don’t think of groundwater in terms of a body of water in a cavity below ground. Shallow groundwater is usually in saturated soils. When you dig a hole, surrounding pressure in the walls of the hole forces the water to collect into the void. Even in wells the water is coursing its way through sands and gravels and your well casing has perforations on it that allow that water to flow in and keep the sand and gravel out.