See the article https://support.apple.com/en-in/HT205749
https://support.apple.com/en-us/HT204085
Point number 4 - If you choose to "Approve Later" when signing into your Apple ID, you need to approve with an old passcode or from another device when prompted. If you are unable to approve,
On new Mac iCloud Keychain is not set up the code is generated you are either using same Apple ID and password in new Mac that was used in old Mac , if you remember that old 6 digit security code it can be reused .
Or you are about to sign in with a different Apple ID and password .
Read this also - https://support.apple.com/en-in/HT203783
https://support.apple.com/en-in/HT202861
In old Mac the iCloud Keychain was set up so it didn't prompted the code and you filled up on the upcoming pop up appeared on the desktop and on the trusted mobile number .