Gamma-ray spectroscopy provides a wealth of information about acceler- ated particles in solar flares, as well as the ambient medium with which these energetic particles interact. The neutron capture line (2.223 MeV), the strongest in the solar gamma-ray spectrum, forms in the deep atmosphere. The energy of these photons can be reduced via Compton scattering. With the fully relativistic GEANT4 toolkit, we have carried out Monte Carlo simulations of the transport of a neutron capture line in solar flares, and applied them to the flare that occurred on 2005 January 20 (X7.1/2B), one of the most powerful gamma-ray flares observed by RHESSI during the 23rd solar cycle. By comparing the fitting results of different models with and without Compton scattering of the neutron capture line, we find that when including the Compton scat- tering for the neutron capture line, the observed gamma-ray spectrum can be repro- duced by a population of accelerated particles with a very hard spectrum (s ≤ 2.3). The Compton effect of a 2.223 MeV line on the spectra is therefore proven to be sig- nificant, which influences the time evolution of the neutron capture line flux as well. The study also suggests that the mean vertical depth for neutron capture in hydrogen for this event is about 8 g cm-2.