As to why externally writing XMP can sometimes fail: various reasons, including a cloud-sync or similar process operating within that part of the file system (OneDrive, iCloud, whatever) and conflicting with standard file operations - also, this can relate to user-specific or application-specific file and folder access permissions.
But IMO it is important to say: writing metadata to the external files (as XMP data, loosely speaking) is not a necessary component of editing in Lightroom Classic. The Catalog always holds your successive editing steps in any case.
A "metadata warning" does not say anything about the validity of that image's editing within the Catalog. It only speaks to the current relationship between that editing, and any duplicated editing info which may be also present externally.
In fact the Catalog holds some information against each image which can never be externally written. Examples: prior editing History steps; Collection membership; Stacking; the entire existence of Virtual Copies.
Making Catalog backups reasonably often is your best protection (into distinct storage hardware ideally, not sharing hardware with your working setup ideally). This should be accompanied by a good separate backup regime for the image files themselves, which are not included when you backup the Catalog.
As I see it ALSO externally writing XMP metadata is only even useful, in two circumstances:
The first is: if for some reason you want to access these same image files by another method that does not involve a LrC Catalog, using software that will nonetheless properly implement Adobe-specific metadata describing the latest editing state that was achieved inside the Catalog.
The other way it may help is: say you last backed up your Catalog on Monday evening. And now it's Wednesday, and you need to revert to that Monday backup for whatever reason. If while you worked during Tuesday, external XMP was being continually written out - then your latest work (done meanwhile, since that Monday backup happened) can be at least partially retrieved from there. Two scenarios: an image was already imported before the Monday backup, in which case you can now Read external metadata to update with your latest Tuesday editing on that. Or, the image only got imported during Tuesday, in which case if you now repeat the import, it arrives reflecting the latest (Tuesday) editing state that has been written to that.