I had this problem for a while on my Iphone 7s this is all what I did:
1st - Confirm that it is indeed a software problem. I did it by using the ebay App and in the search used the camera functionality. Indeed my camera and flash were working fine from ebay, so it must be a software issue.
2nd - I did a Reset All Settings. I'm not sure if this is necessary but as I mentioned I'm listing all the things I did until it finally worked. For this go to Settings - General - Reset - Reset All Settings. Make sure you read about what Reset All Settings will do to some of your configurations like WIFI, Apple Card Pay etc. and take precautionary steps if deemed necessary.
3rd - I removed the NFC Tag Reader from Control Center. Setting - Control Center
4th - I turned on the Flashlight and then opened the Camera. Again, still did not work but I'm listing all I did until it finally worked as I don't know the relationship between all these steps and the final outcome when it finally worked.
5th - Finally, while the camera is opened, hit the 1x button to enter into 2x zoom, voila! The freaking camera is working now!
I hope someone at Apple can take a look at this and resolves the OBVIOUS software issue. Maybe give me a freaking discount! :-)