Origin of star-forming rings around massive centres in massive galaxies at z < 4