IMAP does not work in such scenarios, and frankly, you should not be using it for Exchange mailboxes. You can either use the first-party solution Microsoft offers (https://learn.microsoft.com/en-us/microsoft-365/enterprise/cross-tenant-mailbox-migration?view=o365-worldwide) or a third-party tool, of which there are plenty. The former is free, but might involve some more work on your behalf, compared to a third-party tool. Those in turn are easier to use and might offer additional features on top, but they all come at a price.
We don't usually recommend specific third-party tools to avoid vendor spam, but you can easily find them online.