The magnetic field is one of the fundamental observables in solar physics, whereas solar flares are violent, rapid magnetic energy-release events in the solar atmosphere. Despite decades of observations and theory regarding flare evolution and magnetic-field-related physical processes, the actual magnetic field variations during flares remain poorly understood. Here, using a mid-infrared solar telescope, we investigate the spectroscopic evolution of the Mg I 12.32-µm line during an X1.5-class flare. Owing to the high Zeeman sensitivity of this line, magnetic field strength can be directly determined from the measured line separation. Our analysis reveals apparent magnetic field weakening beneath flare ribbons in the impulsive phase. Radiative–hydrodynamic simulations and atmospheric inversions confirm that the formation height of the Mg I 12.32-µm line increases during the flare. We suggest this apparent field change probably originates either from elevated line-formation altitude or magnetic-field redistribution. This study demonstrates the capability of mid-infrared wavelengths to trace magnetic-field evolution during flares and advances our understanding of the flare energy build-up and release processes.