Even today, some fish & other aquatic critters spend parts of their lives on land, and many land critters spend parts of their lives in water.
So why do they do it?
To find food.
To escape preditors.
And, that most powerful reason of all -- looking for love!
So once fish are spending some parts of their lives on land, then those which grow better lungs & legs get around better, find more food, and eventually, hey! Who needs that cold water anyway, why go back?
As for reptiles, birds & mammals which went the other way, the reasons were the same -- once you make your living in the water, then any new adaption to improve your swimming ability helps find more food, etc., etc....
Does that answer your question?
Nope - they all should have done it, not just a few ....
The diagram is missing quite a few transitional forms.