Locked modes (LMs) will be one of the major causes of disruptions in the ITER tokamak. Disruption mitigation systems (DMSs), such as massive gas injection (MGI) or shattered pellet injection (SPI), are expected to be deployed in pre-disruption discharges with large pre-existing locked modes. A series of target plasmas with an m/n = 2/1 locked mode induced by resonant magnetic perturbation (RMP) penetration was terminated by an MGI on the J-TEXT tokamak. The penetration of the injected impurities during the process was diagnosed using a fast frame visible camera and a multi-channel polarimeter-interferometer (POLARIS) in combination. The electron temperature evolution during thermal quench (TQ) is also shown in detail. It is found that both the phase and width of the 2/1 mode have an effect on MGI shutdown dynamics. When the mode is larger than the critical width, the penetration depth and assimilation of impurities can be enhanced during pre-TQ, leading to a faster quenching process if the relative phase between the O-point of the 2/1 mode and the MGI valve is ∆φ = +90°. Conversely, the penetration depth and assimilation of impurities are suppressed, leading to a slower TQ when the relative phase is ∆φ = −90°. The toroidal radiation asymmetry is worse with the locked mode. The results suggest that the 3D effect between the injected impurities and the 2/1 locked mode is important during the disruption mitigation process.