A webmail login can ask for a second factor: a code from an app, an SMS, a tap on your phone. IMAP cannot. The protocol has exactly one LOGIN command carrying a username and a password, and there is nowhere in it for a second step.
Providers all solved this the same way. The account password stopped being accepted over IMAP at all, and external clients get a separate one instead: an app password. It is a long random string that works only for mail protocols, cannot sign you in to the web interface, and can be revoked with one click without touching your real password.
That leads to a practical point worth keeping: handing a migration tool an app password is safer than handing it your account password. Even if it leaks, nobody can enter the account, change the password, or read your files.