Here's a solution. Once it’s applied, the solution should continue to work for all files of that kind (jpg or png or heic, etc.) everywhere on your Mac.
1. When a picture in Messages insists on opening in the wrong app, go ahead and let it open.
2. When it’s open, look for the name of the file (at the top of the image window or elsewhere, depending on the program).
3. When you have the name, open a finder window and press ⌘-f, then type or paste the file name into the space at the upper right of that window. For this to work, you’ll need to search system files, too; to do this, press the “+” at the upper right of the search window, then click on the drop-down window under “Kind” or “Name” (or whatever comes up for you) and choose “Other…”. A window will open. Search that window for “system”. Tick the box on the same line as “System files” and click “OK,” which will close the window.
4. Now you should be back in your original search window. To the right of “System files” select “are included.”
5. You should now be able to find the file that opens in the wrong app. Click on it and press ⌘-i.
6. A finder info window should open. About two-thirds of the way down that window it will say “Open with:” Click on that and pick Preview, or whatever app you want to have open that kind of file in the future.
7. Just below there, click “Change all…” IF YOU WANT that kind of file to open in the selected app EVERYWHERE on your Mac. If you do want that, click “Continue” on the window that pops up, and you’re done.