Setting 2FA with device logged in with different account
Yes, it is relatively straightforward if you follow Apple's guide here:

https://developer.apple.com/support/account/authentication/

Look under the heading "How can I use different Apple IDs for iCloud and my Apple Developer Account".

The basic idea is that you enable 2FA for you developer account. The easiest way to do that with the devices you've got, is to create an extra user on your Mac. Login to that user on the Mac and sign in with your developer account and enable 2FA at System Preferences > iCloud > Account Details > Security.

Then on your ordinary, main account and your iPhone, you just need to add the developer account as an extra iCloud account for 2FA. On the iPhone you go to Settings > Passwords &amp; Accounts > Add Account > iCloud. On the Mac you go to System Preferences > Internet Accounts > iCloud.

Now that everything is setup, you can delete the temporary user again.

So now even though your main iCloud account is B, you'll receive 2FA codes for both account A and B on your iPhone and Mac.