How setup Mail.app IMAP to migrate Mail Server
You can


copy the whole content of the old IMAP account into a local archive
enable/configure the new IMAP account
copy the local copy into the new IMAP account


You can probably also do this directly (old IMAP to new IMAP) but I run into IMAP implementations in the past which weren't too stable during batch copying. So keeping a local copy (at least for a short time) is recommended.

If a local copy is not possible due to mailbox size, you can alternatively try to copy old IMAP to new iMAP folder by folder. Be sure to verify each step at least visually.