It is the first step of Gabriel's phthalimide synthesis. The hydrogen bonded to nitrogen is sufficiently acidic due to two α-carbonyls.
The conjugate base formed above act as nucleophile in the subsequent step of reaction. As shown above, the nucleophile exist in three resonating form, one may think of oxygen being the donor atom in the nucleophilic attack. However, nitrogen act as donor as it is better donor than oxygen.
Bromine is not substituted in the above reaction as it is in resonance with benzene ring giving partial double bond character to C−Br bond, hence difficult to break.