Restoring an accidentally migrated mail user to On-Prem Exchange

We recently migrated most of our users to Office 365, and due to a miscommunication, three users that should have stayed on premises were migrated, converted to the RecipientTypeDetails RemoteUserMailbox, and had their local mailboxes disconnected.

Reconnecting their mailboxes failed as they were of the wrong user type:

Connect-Mailbox -Identity "Name Surname" -Database "DB10" -User "Name Surname"
This task does not support recipients of this type. The specified recipient Name Surname is of type User. Please make sure that this recipient matches the required recipient type for this task.
    + CategoryInfo          : InvalidArgument: (Name Surname:UserIdParameter) [Connect-Mailbox], RecipientTaskException
    + FullyQualifiedErrorId : E9DDBACA,Microsoft.Exchange.Management.MapiTasks.ConnectMailbox

The solution was to remove the Exchange properties from the user object:

Get-Recipient -Identity "Name Surname" | Disable-RemoteMailbox

After confirming this is what we want to do, the mailbox could be safely reconnected.

However: After reconnecting the mailboxes, the users still couldn’t start Outlook: The program failed to start with an error message “The set of folders cannot be opened”.

The issue here is that DSAccess caches an erroneous query, and the solution is to update the status of disconnected or soft-deleted mailboxes:

Clean-MailboxDatabase -Identity "DB10"

After this, the users could continue working as usual.