The defender joined the Gills at the beginning of January on loan and has made the switch permanent after the initial deal expired following Tuesday's win over Northampton.
The 27-year-old had joined Brentford from non-league Tonbridge Angels in 2009 before going on to make 115 appearances for the Bees.
Martin Allen's side have kept three clean sheets in the five appearances Legge has made since arriving at Priestfield.
- Sports & Recreation
- Tonbridge Angels