We investigate the behavior of the pseudo-critical temperature of N f = 2+1 QCD as a function of a static magnetic background field for different values of the pion mass, going up to mπ ≃ 660 MeV. The study is performed by lattice QCD simulations, adopting a stout staggered discretization of the theory on lattices with Nt = 6 slices in the Euclidean temporal direction; for each value of the pion mass the temperature is changed moving along a line of constant physics. We find that the decrease of Tc as a function of B, which is observed for physical quark masses, persists in the whole explored mass range, even if the relative variation of Tc appears to be a decreasing function of mπ, approaching zero in the quenched limit. The location of Tc is based on the renormalized quark condensate and its susceptibility; determinations based on the Polyakov loop lead to compatible results. On the contrary, inverse magnetic catalysis, i.e. the decrease of the quark condensate as a function of B in some temperature range around Tc, is not observed when the pion mass is high enough. That supports the idea that inverse magnetic catalysis might be a secondary phenomenon, while the modifications induced by the magnetic background on the gauge field distribution and on the confining properties of the medium could play a primary role in the whole range of pion masses.