This superstition comes from funerals when a dead person wears socks. Sleeping with your socks on is considered to be an imitation of the funeral tradition, which means you are speeding up the process of your death by voluntarily performing a funeral action.