CentOS 7-8 are no longer fully supported, but there is a workaround for this error. There are other possible issues for the failed to synchronize cache for repo appstream error, but this seems to fix it every time for us.
cd /etc/yum.repos.d/
sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
dnf update
Other possible issues are time not correct on server and/or expired DNF cache.