The Hokage is the most suitable ninja in the village who is chosen for the job by the previous hokage the 3rd was getting on in years and was looking for a successor he saw a very promising candidate with a great disposition in Jiraiya's pupil and choose him to be the next hokage.

When the 4th died there was no other ninja qualified for the job as Jiraiya (the only suitable ninja) was gone so the 3rd had to step up and become Hokage again.