Following hysterectomy, the reproductive tract is separated from the abdominal cavity, so the sperm has nowhere to go, and it gets eventually expelled from the body along with the normal vaginal secretions.