We present deep optical and near-infrared imaging of the rich cluster A 2218 at z = 0.17. Our optical imaging comes from new multicolour Hubble Space Telescope WFPC2 observations in the F450W (A450), F606W (V606) and F814W (I814) passbands. These observations are complemented by deep near-infrared, Ks-band imaging from the new INGRID imager on the 4.2-m William Herschel Telescope. This combination provides unique high-precision multicolour optical-infrared photometry and morphological information for a large sample of galaxies in the core of this rich cluster, at a look-back time of ∼3 Gyr. We analyse the (B450 - I814), (V606 - I814) and (I814 - Ks) colours of galaxies spanning a range of a factor of 100 in K-band luminosity in this region, and compare them with grids of stellar population models. We find that the locus of the colours of the stellar populations in the luminous (≳ L*K) early-type galaxies, both ellipticals and S0s, traces a sequence of varying metallicity at a single age. At fainter luminosities (≲ 0.1L*K), this sequence is extended to lower metallicities by the morphologically classified ellipticals. However, the faintest S0s exhibit very different behaviour, showing a wide range of colours, including a large fraction (30 per cent) with relatively blue colours that appear to have younger luminosity-weighted ages for their stellar populations; 2-5 Gyr. We show that the proportion of these young S0s in the cluster population is consistent with the observed decrease in the S0 population seen in distant clusters, when interpreted within the framework of a two-step spectroscopic and morphological transformation of accreted spiral field galaxies into cluster S0s.