Please try a force reset procedure as shown, this will determine if this is a software issue.
- Press and quickly release the volume up button.
- Press and quickly release the volume down button.
- Press and hold the side button until you see the Apple logo
Force restart iPhone - Apple Support
If that doesn't rectify your issue, then this is likely a hardware issue in which you need to visit your nearest Apple Store's Genius Bar or Apple Authorized Service Provider for diagnostics and evaluation.
Genius Bar Reservation and Apple Support Options - Apple