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.
- Sports & Recreation
- Myles Weston