About 40 minutes after TLI the Apollo Command Service Module (CSM) separated from the third stage, turned 180 degrees and docked with the Lunar Module (LM) that rode below the CSM during launch.
If it were to remain on the same trajectory as the spacecraft, the S-IVB could have presented a collision hazard so its remaining propellants were vented and the auxiliary propulsion system fired to move it away.