Sometime after the Battle of Jakku, Jedi Master Luke Skywalker discovered or built this Jedi Temple on an unknown planet, to serve as a Jedi academy; in order to train a new generation of Jedi Knights and establish a New Jedi Order, realising that the old Jedi teachings as well as the old code were flawed and to avoid the New Jedi Order from making the same mistakes as the Old Jedi Order - Luke altered some of the Jedi teachings and code.
The First of Luke's students was his nephew, Ben Solo and several other Force-users, unfortunately, his nephew fell to the Dark side when Ben when discovered that his uncle, Luke wanted to kill him, because he was afraid of how stronger connection to the Dark side of the Force was. He then killed most of Luke's apprentices and the rest of his fellow Jedi joined him.
Luke was in horror as he was unable to stop the Jedi massacre, Luke and his astromech droid R2-D2 watch as most of the Jedi Temple was burning, Luke when in search of Ahch-To Jedi Temple, as he was guilt ridden over his students' deaths, and Ben and his other students' fall to the dark side. Luke would remain in hiding on Ahch-To, until the time would come when he dies; so that the Jedi Order would end with him.