Sounds like your system is overheating! Depending on the size of your Lightroom project it maybe too much for your system in its current state.
Over time the fans and the heatsink fins get clogged up with dust and other debris, the more choked up the less cooling, SMC will shut you down once you hit the limit of the systems cooling.
So to start with I would install a good thermal monitoring app like TG Pro is it by far the best out there! In your case you’ll want the full package to gain the logging. Now start monitoring! Hopefully you can get the system to wink out, but this time let the system cool down and see if you can restart it by pressing the power button lightly (like you would if in sleep mode) If you can do that your data should be saved and you can review things from the log. Post a screenshot if you can when your system is toasty so I can see the sensors and the fans RPM. Do make sure you capture all of the sensors you may need to grow the window to get a single snapshot or take two after sliding the window down to get the stragglers following this guide to post your captures Adding images to an existing question
I would also run the onboard diagnostics as well. Restart your system and press the D key to enter. I don’t think you’ll get an error but its a good idea to check.
OK, we’ve talked a lot about diagnostics so far and getting start point of your temps now.
So what to do to fix this? Assuming you have a dust issue you’ll need to open the system to clean things out. Get a small soft paint brush as well as can of can’ed air with a snorkel as you’ll need it. Here’s the guide to open your system follow this guide to the letter! iMac Intel 27" EMC 2546 Fan Replacement you’ll also need a special tool to cut the adhesive tapes which holds your display on which is part of this kit iMac Intel 27" (2012-2019) Adhesive Strips and you may want to get a second set of tapes just in case. I also find these helpful Plastic Cards I would get two sets (four). Using some cardboard you can make this or just order it as well iMac Service Wedge to hold your system in place as you work on it
And lastly, I recommend getting a small J roller and variable temp heat gun or hair drier as you will need the pressure from the roller and the heat from the heat gun to help set the adhesive so the screen is properly attached when you’re done.
But before you go into your system lets make sure we are are the right track.