AccountId field on the User object is read only. It is derived from Contact’s AccountId field. We cannot update AccountId on the User object. The Contact record’s AccountId field should be updated so that it will also gets reflected on the User object.
SOQL:
SELECT Id, ContactId, Contact.AccountId,
AccountId, Account.Name
FROM User
WHERE Id = '0053t00000AHXRxAAP'
Sample Apex Code to Update AccountId:
update new Contact(
AccountId = '0013t00002gWFshAAG',
Id = '0013t00002XXRyDAAX'
);
When we use the above sample apex code, the Account on the Contact will be updated. So, the AccountId on the User will also map to this new Account Id. We can use the same SOQL shared in this post to verify it.