
Exception:
You can’t create a contact for this user because the org doesn’t have the necessary permissions. Contact Salesforce Customer Support for help.

The Salesforce Exception “You can’t create a contact for this user because the org doesn’t have the necessary permissions. Contact Salesforce Customer Support for help.” is thrown when the ContactId on the User record is set to null or blank for an external user.
Resolution:
IsPortalEnabled should be set to false to remove the associated Contact from the Salesforce Experience Cloud User.
Sample Code:
update new User(
Id = '<UserId>',
IsPortalEnabled = false
);