When iPhone and Mac are signed in with same Apple ID and password on the same network , the Mac and iPhone are at home the code appears in phone , if you turn off iPhone , what will happen still the code will appear on Mac desktop screen as location services is turned on ( it will find through IP address ) and find my Mac is also turned on .
It depends how you use the services , if Mac is at home the Mac is a primary device 2FA is originally created from Mac and not from your connected devices .
As you mentioned - but I could never set it up properly on Apple Mail.
What problems do you face in Mac , please clarify .