Your verification codes are valid for approximately five minutes. After that time, they won't work and you need to get a new verification code.
When using text message verification codes, you can refresh the Two-Factor Auth page, and re-click Setup text message verification codes then Send verification SMS. This sends a fresh code to your mobile number.
When using the verification app, you can refresh the generate codes in order to require a fresh code. If you're having trouble generating a usable code, you could try closing and reopening the verification app on your device.