Your Mac needs to trust your iPhone or iPad—and vice-versa. Apple added a Trust button to iOS years ago that appears when a device is connected to a computer, requiring a phone or tablet be unlocked and the connection confirmed. This was another layer in attempting to ensure that a device’s owner really wanted that computer to have access.
However, you can run afoul of this provision. My dad wrote to me from a small island on Greece recently after he’d swapped in a Greek carrier’s SIM for his unlocked AT&T iPhone. While voice, text, and data worked fine, whenever he plugged his iPhone into his laptop, he neither received a Trust dialog nor could get his phone’s images to appear as available with iTunes, Photos, or Image Capture.