
IsPortalEnabled should be set to false to remove the associated Contact from Salesforce Experience Cloud User.
Sample Code:
update new User(
Id = '<UserId>',
IsPortalEnabled = false
);
When the IsPortalEnabled flag on the external user is set to false, it will remove the Contact associated with the External User and make them inactive.