I've also this problem. Since some months ago, the screen of my iMac 27" Mid 2010 started to go black (off) randomly. I know the system is running without problems because I can put my computer in sleep mode (control+shift+eject), and after press a key to awake the computer, the image comes again always. After doing this, sometimes it remains on for hours, sometimes just for few seconds.
I can also work perfectly with another display attached, when the iMac screen goes black, the second display remains on and working. So, I can absolutely discard a graphic related problem.
I don't think it's software related either... because I've tried to start the computer with the Recovery partition, to reinstall the latest Sierra version several times (with the COMBO Update) and always I had the same problem. I've not tried to restore an old version of macOS, but I think it's not necessary... it should work fine with Sierra without problem.
One more thing... and this is curious: you can try to use the flash light of the iPhone very close to the iMac screen and look what happens! In my case I can see all the info there! It's difficult, but if you have a enough power light and you put it very very near to the screen, you should be able to see the icons, the windows, the images, the texts and everything of your desktop or your system running is there, but with the backlight switched off. You can test your computer to see if the same happens to you. In my case, I think it's simple: the problem is that the light of the screen (LEDS) is switched off.
So, I'm 90% sure it's a problem related to the LED DRIVER BOARD, also called the inverter... and sure it should be replaced. But any case, Apple should say something, because although all of our iMacs are out of warranty, I think it's not normal that so many iMacs having the exact same problem. Perhaps this models, after some years of use, start all of them having the same problem with this piece of hardware.