They were not killed. Hagoromo specifically told Naruto that their lives were dependent on their friends. That he could not return them to the living world himself.Both Naruto and Sasuke's hearts stopped beating, so they technically were killed in that sense.