Well I figured it all out. Rey is a clone of Luke, made from his chopped off hand. She was created by Palpatine as a backup, in case Luke doesn't turn. However before she was really developed, she was taken by a rogue space pirate named Lando and was grown in a tube by him and the Millenium Flacon's onboard computer. As we know, fetuses all start female before developing the male chromosome, and since Lando didn't know who she was a clone of, he kept her as a female. Eventually financial difficulties due to gambling losses made him leave her on Jakku. Now, in order to stop the reincarnated evil emperor Palpatine, Luke's essence must be allowed back into the land of the living, but he needs a host with an adequate midochlorian count. Only Rey qualifies (because she is actually him). Unfortunately for the transfer to be complete, a sacrifice is needed, so Rey pretends to fall in love with Kylo only to betray him, knowing that this will lead to him cutting off her hand. This enables the return of Luke, and the Rise of the Skywalker.