There are various reasons why your iPhone 7 might suddenly black out while in use. Here are the main culprits:

1. iPhone 7 in DFU Mode (Device Firmware Upgrade)
DFU Mode – What is Software Device Upgrade? This mode puts your Apple device into a state where it needs to have its software restored, requiring a reload of the operating system. After restoring in DFU mode, the device will operate more smoothly, experience fewer errors, and clean up all junk files, avoiding situations where the iPhone 7 screen goes blank. You can identify this issue when the iPhone 7 screen remains unresponsive, but calls can still be made, and incoming calls still receive notifications.
Solution: Connect the device requiring restoration to a computer using a cable – install and connect iTunes to the laptop, turn off the phone. Then, keep all buttons pressed even when you see the Apple logo appear to put the device into Recovery mode. iTunes will display a message stating that the iPhone needs to be updated; click on Update, and the computer will download the new firmware for the device. If it takes longer than 15 minutes, the device may prompt you to restore again.
2. Running Too Many Apps on iPhone 7
Leaving multiple apps running in the background without closing them can lead to conflicts between apps. iPhone 7 shuts down the screen as a way of indicating that the phone is overloaded. The quickest solution is to restart the phone.
Solution: Press and hold both volume buttons simultaneously along with the side button until the Apple logo appears on the screen.
3. iPhone 7 Battery Depletion
Improper charging or prolonged use of low-quality chargers can cause the iPhone 7 battery to deteriorate, resulting in it being unable to hold a charge. Consequently, the power supply to the device becomes unstable, leading to the black screen issue, indicating that the device is constantly low on energy and cannot be used.
Solution: Once the battery is depleted, it cannot be used anymore. The only solution is to purchase a new battery.
4. Hardware Issue on iPhone 7
While this iPhone 7 black screen issue is rare, it's not unheard of. It's possible that there was a malfunction during production, only discovered upon usage. If your device is still under warranty, take it to an Apple service center to have the hardware replaced. If the warranty has expired, it's still advisable to visit a service center to diagnose and repair any issues if necessary.
With the information provided above, you now have the best possible solution for addressing the problem of a black screen on iPhone 7.