The reason for that is that P-waves (primary waves) travel faster than S-waves (secondary waves).
If we call

the speed of the primary waves and

the speed of the secondary waves, and we call

the distance of the seismogram from the epicenter, we can write the time the two waves take to reach the seismogram as


So the lag time between the arrival of the P-waves and of the S-waves is

We see that this lag time is proportional to the distance S, therefore the larger the distance, the greater the lag time.