The Holy Prophet (Sallallahu alaihi wa sallam) had the authority to chose between life of this world and the hereafter
As we have just seen, the Holy Prophet (Sallallahu alaihi wa sallam) was given the keys to the treasures of this world and the right to remain in this world. Paradise itself was anxious to kiss His blessed feet. This shows that without the permission of the Holy Prophet (Sallallahu alaihi wa sallam) the angel of death cannot enter His presence. Remaining in this world or preferring the hereafter was left to the choice of the Holy Prophet (Sallallahu alaihi wa sallam).
There is another Hadith about this in Sahih Bukhari:
Translation: Ummul Momineen Hadhrat ‘Aisha (May Allah be well pleased with her) says: I had heard from the Holy Prophet (Sallallahu alaihi wa sallam) that no Prophet goes from this world unless and until he is given a choice between this world and the hereafter. (Sahih Bukhari, Hadith No. 4310; Musnad Imam Ahmed bin Hambal, Hadith No. 26175; Sahih Ibn Hibbaan, Vol. 14, Pg. No. 556)
There is another narration on the authority of Hadhrat ‘Aisha (May Allah be well pleased with her):
Translation: At the time of passing away, the Holy Prophet (Sallallahu alaihi wa sallam) was saying:
Allahumma Rafeeqil A’ala meaning O Allah I have selected meeting with the Ultimate Friend.
Hadhrat ‘Aisha (May Allah be well pleased with her) says: Now the Holy Prophet (Sallallahu alaihi wa sallam) will not remain with us. (Sahih Bukhari, Hadith No. 5988)