Muhammad (May Peace Be Upon Him) was the last prophet and messenger in a series of 124,000 that came to mankind with the message of God's oneness.
He died because he was human, Just like every other messenger that had preceded him.
Allah Say's in the Quran
Say, O [Muhammad], "I am only a man like you to whom it has been revealed that your god is but one God; so take a straight course to Him and seek His forgiveness." And woe to those who associate others with Allah.
(Chapter 41: Verse 6).
and if there is one thing certain in this world... that is that everything living thing must die...
Allah says :
"Kullu nafsin zaikatul maut" meaning – "Every soul shall taste death"
(Chapter 3: verse 185).
And Muhammad being a living creation of God... naturally died when his time came...
Hope that answers your question and Allah knows best.