Either you or someone else may be trying to sign into your Apple Account from an unknown device. As part of Two Factor Authentication, this code would need to be entered before you or anyone else can access your account. You may want to change your Password in case that is information that they know.
Change your Apple Account password - Apple Support
If the message is a scam, you may see a contact number to call. You would not want to do this as it would be the scammer looking to get your personal information.