Galaxy sizes correlate with many other important properties of galaxies, and the cosmic evolution of galaxy sizes is an important observational diagnostic for constraining galaxy evolution models. The effective radius is probably the most widely used indicator of galaxy size. We used the TNG50-SKIRT Atlas to investigate the wavelength dependence of the effective radius of galaxies at optical and near-infrared (NIR) wavelengths. We find that, on average, the effective radius in every band exceeds the stellar mass effective radius, and that this excess systematically decreases with increasing wavelength. The optical g-band (NIR Ks-band) effective radius is on average 58% (13%) larger than the stellar mass effective radius. Effective radii measured from dust-obscured images are systematically larger than those measured from dust-free images, although the effect is limited (8.7% in the g-band, 2.1% in the Ks-band). We find that stellar population gradients are the dominant factor (about 80%) in driving the wavelength dependence of the effective radius, and that differential dust attenuation is a secondary factor (20%). Comparing our results to recent observational data, we find offsets in the absolute values of the median effective radii, up to 50% for the population of blue galaxies. We find better agreement in the slope of the wavelength dependence of the effective radius, with red galaxies having a slightly steeper slope than green-blue galaxies. Comparing our effective radii with those of galaxies from the Siena Galaxy Atlas in separate bins in z-band absolute magnitude and g-z colour, we find excellent agreement for the reddest galaxies, but again significant offsets for the blue populations: up to 70% for galaxies around Mz=-21.5. This difference in median effective radius for the bluer galaxies is most probably due to (abridged...).