Those codes come across as actual SMS messages to the associated phone number. It appears on your laptop only when the phone is near enough to it that the "continuity" feature is engaged. You should be safe from this threat as long as the laptop isn't lost very nearby.
Sending and receiving non-iOS/iMessage texts require your phone to be near your computer. I don't believe any company sends 2FA codes to you through iMessage.
I've never seen this behavior with my own devices, and cursory searching turns up similar results. Certainly I could be wrong, so can you point me to any references that describe the "proximity not required" behavior?