When you snap a picture with a smartphone, tablet, or camera, the date and time are encoded in the image’s EXIF (Exchangeable image file format) metadata. It’s embedded so that it can be used later by any software that works with the image.
However, as readers will testify, it’s very easy to wind up with a mismatch between the time and date recorded in an image and what they see for creation date in the Finder on a Mac. Photos for macOS seems to have made this worse in Catalina. Export an image from Photos in Mojave or earlier versions of macOS using File > Export > Export Unmodified Original, and Photos uses the same timestamp you can view via Window > Info.