The 27-year-old will link up with former team-mate Myles Weston and will remain with Martin Allen's men until January 29, with the move then expected to be made permanent.
The paperwork has been lodged in time for Legge to be considered for Gillingham's game at Southend on New Year's Day.
In just over three seasons at Griffin Park Legge made 115 appearances for The Bees and scored 10 goals.
Bees boss Uwe Rosler told the club's official website: "I think the move is in the best interests of Leon and us in that we fulfil his wish for regular playing time.
"I want to thank him for the service he gave the club and to me. He is an honest lad and gave his all and was an important member of the squad."