I had a similar problem when joining an Azure VM Windows 2022 Server to an Azure-based Active Directory domain. It said the server was already joined to the Azure AD.
"This device is joined to Azure AD. To join an Active Directory domain, you must first go to settings and choose to disconnect your device from your work or school"
But the system properties just showed the machine as part of a Workgroup. there was nothing to disconnect from.
The solution was to run DSRegCmd /Leave from an administrator command prompt. Then I could add the server to my Azure AD.