I had this problem and came across this link: https://wwwsunzala.com/fixed-apple-id-an-unknown-error-occurred/
The author states:
Did you notice you cannot add Google, Yahoo or other accounts too? I could not and after noticing this I realized the problem has nothing to do with iCloud or Apple server. It’s just my local machine which needs a fix.
After days of investigation, I found the Accounts/ iCloud local database is damaged and I have to reset it. I was pretty skeptical but held my breath and ran this:
sudo -v ; killall -9 accountsd com.apple.iCloudHelper ; defaults delete MobileMeAccounts ;
mkdir ~/Library/Accounts/Backup; mv ~/Library/Accounts/*.sqlite* ~/Library/Accounts/Backup/ ;
killall -9 accountsd com.apple.iCloudHelper ; sudo reboot
It worked! :shrug: