I’d have to look up what the JTAG pins on the Photon are, but this sounds a bit like an old known issue
Start-Up/Flashing “troubles” with D-pins (summarized)
OK, D5 (as D7 too) is still a JTAG pin with pull-up during bootup.
https://docs.particle.io/datasheets/photon-datasheet/#jtag
The common cure is to use A-pins instead.