The result leaves Lille on eight points at the top of Group H, a point ahead of Milan with two more games to play with qualification to the knockout stages still not assured after Sparta Prague moved up to six points with victory over Celtic.
Lille nearly took an early lead when Sandro Tonali lost possession near his box, allowing Yusuf Yazici to take a shot on goal. However, Milan goalkeeper Gianluigi Donnarumma was relieved to see it curl wide.
Tonali then made up for his near-costly error with a sublime through ball in the opening minute of the second half, releasing Ante Rebic who pulled it back for Castillejo to score the opening goal.
Lille pulled one back almost 20 minutes later when a quick throw-in caught Milan's defence off guard and a smart passing move allowed Jonathan David to control a cross to set up Bamba, who found the back of the net with a deflected shot.
Lille host Sparta Prague next week while Milan host Celtic.