Just as it seemed all hope was lost for the Resistance at the end of The Last Jedi, the actual last Jedi showed up with a new hope in the form of a cool Force projection from across the galaxy. Using this cool remote control avatar of himself, Luke bought time for the remaining survivors of the Rebellion to escape and scatter to the winds, to plant the seeds of a new, future Rebellion. And then, for no apparent reason, he died.
But why? It's possible, of course, that the strain of sending his astral form across the galaxy proved too much for Luke. It's also possible that being repeatedly shot with laser cannons and stabbed by Kylo Ren's lightsaber actually did damage to Luke's physical form—after all, Kylo was able to make physical contact with Rey in their shared Force vision. It's also possible that Luke simply decided to become a Force ghost after fulfilling his destiny. Perhaps he finally found his own personal balance and simply decided to go out on a high note.
All we know for sure is, one second Luke was fine, and a second later, he raptured on out of there and left behind a sweaty old Jedi snuggie for the temple cleanup crew to deal with. But why is anyone's guess.