This error occur due to the terminal can't access to full disk. To fix it, go to System Settings → Privacy & Security → Full Disk Access. Enable the checkbox for your terminal app. It will restart the terminal, after which you will be able to successfully run xattr on the files you want.