Like any other waves seismic waves speeds will depend on the material properties ( in our case elastic moduli and density). Recall in Optics, and Wave study (like sound etc. ) your learn how waves interact with different material through refraction, reflection etc. Well
the same types of interaction between waves and the subsurface geology (i.e. the rocks) are common too are observed in seismograms: Refraction, Reflection, Dispersion, Diffraction, and Attenuation
To explain you question we only need to consider the first two - Refraction, Reflection.
Refraction and Reflection are caused by difference in Rock properties. The amplitude, speed, direction and angle of reflection of the wave depends strongly on the angle that the incidence wave makes with the boundary and the contrast in material properties across the boundary. In some instance for some angles all the energy can be returned into the medium containing the incident wave.
The interaction between a seismic wave and a contrast in rock properties is such that an incident P wave generates transmitted and reflected P- and S-waves. Likewise, when an S-wave interacts with a boundary in rock properties, it too generates reflected and refracted P- and S-waves. The actual interaction is involved but this should answer your question.