Here are various threads and solutions:
https://discussions.apple.com/thread/256221052?sortBy=oldest_first
The phone number assigned to your SIM may be registered to a different Apple Account. If applicable, this will prevent forwarding of incoming messages to the Messages App on your iPhone; you may need to temporarily deregister your phone number:
Deregister iMessage on your iPhone or online —> Deregister iMessage on your iPhone or online - Apple Support
_________
The first part of this reply appears to provide the same reasons as the third post below this one. It then suggests
Try “Get code another way. On the verification screen, tap: Didn’t get a verification code?
Then choose:
Send via Text
Call this number
Use another trusted device
https://discussions.apple.com/thread/256054763?answerId=261378427022
The real fix is: Your new account password MUST have a special character in it... BUT the flow for account creation from the Accept Invite email does not verify you've done that.
https://www.reddit.com/r/applehelp/comments/1dfsw8m/verification_codes_cannot_be_sent_to_phone/
I clicked resend code like 30 times until I finally received it
https://discussions.apple.com/thread/256193494?answerId=261734267022
Your phone number has been temporarily rate-limited by Apple due to multiple OTP [One Time Passcode] attempts. Wait 8–24 hours, try using a trusted device to generate a verification code, confirm your trusted number, or use account recovery if no trusted device is available. If the block persists longer than 24 hours, contact Apple Support to reset the rate limit.