Perform this test in an effort to advance troubleshooting. Compose a message to yourself but send it as SMS text instead of using Apple's iMessage service (which those 2FA codes don't use). Ideally you would perform that test on a non-Apple device, but you can use an iPhone. To do that with your own iPhone, start a text message as you normally would.
- A grey iMessage should be in the text field prior to typing, which is merely an indication the recipient (you) is able to receive iMessages.
Tap the blue "send" icon (up arrow) as you normally would. Then, immediately tap and hold the blue message text you just sent. A contextual menu will appear.
- If you do not tap and hold that blue message quickly enough, the correct contextual menu will not appear, so try again.
Tap Send as Text Message.
Does it take an equally long time for that message to appear on your Mac? If so it would confirm the problem lies with your cellular service provider, otherwise it suggests the problem lies with your Mac.
Presumably, you are using Safari when this problem occurs? Are you using anything that may contribute to that problem, such as a VPN?