I believe you mean what Apple calls a "verification code".
Make sure the number is still listed as a trusted number. The below is based on the section "About trusted phone numbers and trusted devices" in the article Two-factor authentication for Apple Account - Apple Support
To see, add, or change your trusted phone numbers use one of these methods:
● On your iPhone, iPad, or iPod touch: Go to Settings > your name > Sign-In & Security. Tap Two-Factor Authentication, tap Edit (above the list of trusted phone numbers), then enter your device passcode when prompted. Add or remove the number, then tap Done.
● On a Mac computer choose Apple menu > System Settings (or System Preferences), then click your name (or Apple ID). Click Sign-In & Security, then add or remove a trusted phone number.
● Using a web browser:
1) Go to https://account.apple.com and sign in.
2) Follow Account Security options until you find one letting you change trusted numbers,
3) Click "+" to add a new number (you may be required to verify this number).
4) If you wish to remove an old number, click "-" next to the number.
If you still have issues, contact Apple. While what is posted in another reply about Apple no longer trusting specific numbers, I have never seen that mentioned on this forum before and the poster does not provide any references to that being an Apple procedure. Do you see any kind of error message when you try your first number?
To speak with somebody at Apple, refer to this page for Apple Support features ➔ Contact - Official Apple Support
Select from the presented options until you find a solution for your issue, or see if there is a chat or phone call contact method offered lower on the page under “Get more help” (you sometimes have to narrow down the options multiple times before this is shown). If you do not see your issue, keep experimenting with any series of selections until you reach one that offers a chat session or a telephone call and get the representative to redirect you.
This support article has various country telephone numbers for contacting Apple for support and service ➔ Contact Apple Support - Apple Support For some countries look under “Other” listing at the end of the list. Not every country has telephone support, and phone numbers may only work when calling from the same country.