If was explained off camera, that during the short period after meeting Rey and on the the Falcons journey to see Maz, Han was instantly drawn to her and couldn't understand nor explain the connection. Within minutes they bonded and he became her Father figure & Mentor. He then immediately holo communicated with his friend & space lawyer Maz and had her draw up a contract giving possession of the Falcon & his Wookie pet to Rey since he was on the outs with his wife, General Leia. It then became a galactic bond that not even his wife Leia, nor son Ben (who apparently hated the ship anyway cause his dad had a stronger bond to the Falcon & his pet Chewie than his own son), could contest in the galactic court.
It was all in the canon Disney Star Wars novel. "Rey..... The Galaxies feminist leading all powerful unyielding perfect at everything even without training force wielder and beacon for the new Rebellions attempt to yet again thwart the Empire, uh First Order, from ruling the Galaxy and oppressing all life under their iron rule by the ancient force known as Snoke, uh Kylo Ren, who used to be the son of the Rebel Heroes & Legends Han Solo & General (sometimes called Princess) Leia but who have now let down the galaxy after mistakenly entrusting their's son's future to the former Hero Legend and Jedi Master Luke Skywaker Leia's twin brother & Ben's uncle who let Ben be corrupted by the evil and ominous Snoke and who is now an old grumpy Hermit living on an unknown forgotten planet and being taken care of by alien space nuns and turned his back on everyone he loved even after numerous times of putting his own life in danger to save them and the Galaxy and his father Darth Vader cause in life like most people he just simply gave up after his 1st complete failure of training his nephew even though he ultimatly succeeded at everything else previously through hard work and determination".
It is truly and amazing and enthralling novel and a must read for fans of the new Disney ST to help understand everything going on so the directors and writers didn't need to wast time trying to explain things to the audience on screen. Best SW novel ever.