Only when the CSM/LM was on its way to the moon did the S-IVB undock from the spacecraft. But by then it had the same lunar-bound momentum as the spacecraft. On the Apollo 8, 10, and 11 missions NASA let the S-IVB stage follow a ballistic trajectory that had it pass by the moon and go into into orbit around the sun. But on Apollo 13, NASA kicked the S-IVB on to a trajectory that would have it impact the lunar surface.
TOP 10: Most Amazing Rescues
The reason goes back to Apollo 12. When Pete Conrad and Al Bean landed on the moon, they brought along a series of science instruments. Among them was a seismometer, an instrument designed to register ground displacement on the moon to give scientists a look at our satellite's internal structure. Apollo 11 also left a seismometer on the lunar surface, but it fell silent after just three weeks. So it was for the benefit of the scientists reading data from Apollo 12's seismometer that NASA crashed Apollo 13‘s S-IVB into the moon.
NASA tracked Apollo 13's S-IVB by radio signals after spacecraft separation, enabling engineers to accurately predict the time and place the impact would occur. When Apollo 12's seismometer registered a series of vibrations originating from a point about 83 miles away, they knew it was the spent rocket stage. In that instant, it weighed 29,599 pounds and was traveling at 8,465 feet per second.