Your Apple ID address is same as rescue mail address , and you can't open rescue mail as you don't know the password of rescue mail account , hence can't view the code in it .
The Apple ID is locked , reset the appleid password after 24 hours using security answers and questions , date of birth .
Go to iforgot.apple.com enter only Apple ID and click on continue .
If you have checked the box ( b ) of answer security questions , in that scenario the password can also be reset using the month / day / year of your birthday ( click on the drop down arrows of month , day and year and fill up credentials ) .
An option will be shown ( a ) back ( b ) continue .
Verify your birthday to continue , fill up the credentials and click on continue , a small circle rotates
A window appears answer your security questions , fill up the credentials and click on continue , a small circle will rotate .
It will prompt.
Enter a new password ….
Verify password …..
Your password must be at least 8 characters , include a number , an uppers case letter , & a lower case letter .
So fill up the credentials it will show ( a ) back ( b ) continue .
Click on continue and save .
The rescue mail address is always added in the Apple ID account , sign in with Apple ID account , if it is not yet added create a web mail account say with gmail service .
Make sure this mail address and password should be totally different than your Apple ID address / password see the section of rescue mail address in this article https://support.apple.com/en-in/HT201356 in the same Mac open a new tab ( press command and T keys ) sign in with your gmail account here in the web mail account you will see this code , come to the old tab in which apple id account is already opened , fill up the code in the fields and click on done to save .