Seems Sidious had multiple plans for Luke in play. Furthermore he seems to have had a Force-Bond with Luke just like Rey and Kylo Ren.
Could Sidious’s inability to sense Luke when he came to Endor have been because of the Force Bond? Was his claim of having foreseen Luke coming to Vader be the result of the Force Bond as well even if he didn’t know Luke was at the Death Star when making his decision?
Sidious’s survival in whatever form after death probably didn’t effect the Force Bond which probably allowed Sidious to control Luke for a few seconds causing Kylo Ren to see a crazed Luke poised to kill him.
Once Kylo Ren destroyed the new Jedi Temple it would have been child’s play for Sidious’s consciousness bound to whatever vessel or body he survived in to bring back the idea of exile in Luke’s head as Sidious did tell him “…you cannot escape yourself so easily! Do you hear me?!”