The duration of the wave is fixed as it travels along the string because the speed of each part of the wave profile is the same at every point along the string. This happens because the string is assumed to be a linear medium. The high-frequency parts of the wave (the rising and falling edges at half amplitude, where the displacement is changing fastest) move along the string at exactly the same speed as the low-frequency parts (the peak and the 'flat' leading and trailing sections, where displacement is changing slowest). In technical terms, there is no dispersion.
The profile of the wave in the time domain (displacement vs time at a fixed point on the string) remains the same along the string, even when in regions where wave speed is different. The time delay between any two reference points on the wave passing a fixed point on the string is the same at all points along the string. The 2 reference points cross the boundary and enter the slower region separated by the same time delay, so they retain the same separation in the slower region. Hence the pulse duration is the same in the slower region.
However, in the space domain (displacement vs distance along the string at a fixed instant in time), which is used in the diagram in your question, the length of the wave can change. The wave-length and speed change in proportion, the constant of proportionality being the duration of the wave.
As an analogy, imagine identical soldiers being 'emitted' from their HQ at regular intervals of 5s (ie at constant frequency). When marching along a road at 2m/s they are a constant distance of 10m apart. When they move onto rough ground they slow down to 1m/s and bunch up. Each soldier crosses the boundary 5s ahead of the one behind him, but he has only advanced 5m from the boundary when the next one crosses it. The distance between soldiers (wavelength) falls in proportion with their speed, but the time separation remains 5s regardless of the terrain.
If the high-frequency sections of the wave (steep edges) travel faster than the low-frequency sections (peak and trough) then the pulse gets shorter in the time domain. In this case there is dispersion. This happens when the medium is non-linear. An example is water waves : high-frequency capillary waves caused by surface tension travel faster than low-frequency gravity waves, so the ripple spreads out as it emanates from the origin.
Returning to the army analogy, imagine 2 soldiers are 'emitted' from HQ 50s apart. The 2nd is taller; he marches at the same pace but because his stride is longer he marches at 4m/s along the road compared with 2m/s for the shorter man. When the 2nd soldier sets out they are 100m apart. After another 20s the 2nd soldier has moved closer to the 1st. The 1st is now 140m from HQ, but the 2nd is 80m from HQ. They are now only 60m apart. Not only are they getting closer in the space domain, they are also getting closer in the time domain. Whereas the 2nd soldier left HQ 50s behind the 1st, and reaches the 100m point 100/4=25s behind the 1st, he reaches the 140m point only 60/4 = 15s behind.