The convergent migration of two planets in a gaseous disc can lead to mean motion resonance (MMR) capture. In addition, pairs of planets in or near MMRs are known to produce strong transit timing variations (TTVs). In this paper, we study the impact of disc-induced migrations on the TTV signal of pairs of planets that enter a resonant configuration. We show that disc-induced migration creates a correlation between the amplitude and the period of the TTVs. We study the case of K2-24, a system of two planets whose period ratio indicates that they are in or near the 2:1 MMR, with non-zero eccentricities and large-amplitude TTVs. We show that a simple disc-induced migration cannot reproduce the observed TTVs. Moreover, we propose a formation scenario in which the capture in resonance during migration in a disc with strong eccentricity damping is followed by eccentricity excitation during the dispersal of the disc. This is assisted by a third planet whose presence has been suggested by radial velocity observations. This scenario accounts for the eccentricities of the two planets and their period ratio, and it accurately reproduces the amplitude and period of the TTVs. It allows for a unified view of the formation and evolution history of K2-24, from disc-induced migration to its currently observed properties.