He lost everything but his body when xenhort took over but when he was destroyed his heart and soul were realeased and went to his body which became a nobody thus making him human again but since his nobody was not destroyed he retained his nobody abilities the power of twilight. If this did'nt happen riku would have been obliterated when he entered the realm of light cause he becam darkness just like ansem was obliterated when kh opened.