Residual foreground contamination in cosmic microwave background (CMB) maps, such as the residual contamination from thermal Sunyaev–Zeldovich (SZ) effect in the direction of galaxy clusters, can bias the cross-correlation measurements between CMB and large-scale structure optical surveys. It is thus essential to quantify those residuals and, if possible, to null out SZ cluster residuals in CMB maps. We quantify for the first time the amount of SZ cluster contamination in the released Planck 2015 CMB maps through (i) the stacking of CMB maps in the direction of the clusters, and (ii) the computation of cross-correlation power spectra between CMB maps and the Sloan Digital Sky Survey-IV large-scale structure data. Our cross-power spectrum analysis yields a 30σ detection at the cluster scale (ℓ = 1500–2500) and a 39σ detection on larger scales (ℓ = 500–1500) due to clustering of SZ clusters, giving an overall 54σ detection of SZ cluster residuals in the Planck CMB maps. The Planck 2015 NILC CMB map is shown to have 44 ± 4 per cent of thermal SZ foreground emission left in it. Using the ‘Constrained ILC’ component separation technique, we construct an alternative Planck CMB map, the 2D-ILC map, which is shown to have negligible SZ contamination, at the cost of being slightly more contaminated by Galactic foregrounds and noise. We also discuss the impact of the SZ residuals in CMB maps on the measurement of the integrated Sachs–Wolfe effect, which is shown to be negligible based on our analysis.