Question: why jiraiya had to die?
Answer: Lastly Jiraiya wrote a code on the lord toad to help Naruto figure out Pain's identity, so that he can protect himself against him. ... In the end, death of Jiraiya happened because he wanted to show Naruto that he also never gives up, and provide information about Pain as he is too strong and is threat to konoha.