As a child I was always curious about this. But now I understand how important those rocks are and that they are maintained and replaced. The placement of the stones is engineered.
Benefits include drainage, vibration control, noise control, support.
Just amazed how humans can make rocks useful for railroads.