First you have to manually configure the IMAP settings in Mail. You'll find them here:
https://help.yahoo.com/kb/new-mail-for-desktop/imap-server-settings-yahoo-mail-sln4075.html
Then you need to generate a one-time password for your apple mail app. This is the instruction from Yahoo:
Generate and manage 3rd-party app passwords
Third-party email apps (that do not use
our Yahoo branded sign-in page) require you to enter a single password
for login credentials. To access your Yahoo Mail account on these apps,
you'll need to generate and use an app password. An app password is a
randomly generated code that gives a non-Yahoo app permission to access
your Yahoo account. You'll only need to provide this code once to sign
in to your 3rd party email app.
App passwords remain active - even if you change your main account password. To invalidate an app password you must delete it.
The link to generate that password is here:
https://help.yahoo.com/kb/new-mail-for-desktop/generate-manage-rd-party-passwords-sln15241.html