Microsoft are removing support for most basic authentication in October 2022.
They appear to be starting early disabling basic authentication even when it is enabled in authentication policies.
If you find that is stops working before October then you can access the Microsoft 365 admin center Help & support page using the url: https://aka.ms/PillarEXOBasicAuth

Press the "Run Tests" button to check your basic authentication settings. Then select from the dropdown menu to opt out of IMAP basic auth being disabled (until it is disabled for everyone in October).
More information at the Exchange blog entries below:
Basic Authentication and Exchange Online – June 2021 Update - https://techcommunity.microsoft.com/t5/exchange-team-blog/basic-authentication-and-exchange-online-june-2021-update/ba-p/2454827
Basic Authentication Deprecation in Exchange Online – May 2022 Update - https://techcommunity.microsoft.com/t5/exchange-team-blog/basic-authentication-and-exchange-online-june-2021-update/ba-p/2454827