Pure theory crafting.
Luke wants Rey to find him, when the time is right.
I base this theory on Rey being Luke's daughter. Luke leaves her because things go bad with Kylo, but he understands that Rey is the only way to counter Kylo's power. He leaves her on Jakku and flies away (why? to protect her and to keep Kylo busy).
His plan is to be found when Rey is older, after some "tests", so he can be sure she won't turn to the dark side (like Kylo did). He brings his old lightsaber to Maz and instruct R2D2 to await for Rey's coming. He could have given him some instructions like "wait for an heroic action from Rey", "she must have the lightsaber", "Kylo must be unable to track her", something else...
Even simpler, R2D2 could be in direct contact with Luke, sending him updates on the situation. Luke would then use a remote activation when he's confident enough that his daughter won't follow the knights.
How did R2D2 know that Rey is Rey? He knew how to recognize Kenoby in Episode IV, so he must have some proximity sensor to do that. He already met Rey when she was a child, so he has her data in memory.