Hi, to isolate if it's a software issue, try the following:
Make sure to download the latest iOS update on your phone, go to Settings > General > Software Update.
Force restart your phone by doing the following: press & release the Volume Up button. Press & release the Volume Down button. Then press and hold the Side button (on the right side of the phone) until you see the Apple logo. Test the phone.
If the issue persists, it would be best to restore the phone & install a fresh copy of the iOS software:
Backup your phone - How to back up your iPhone, iPad, and iPod touch
Restore your phone as new - Restore your iPhone, iPad, or iPod to factory settings
Setup your phone - Set up your iPhone, iPad, or iPod touch
After setting up your phone, test your phone again. If the issue persists then bring your phone to the nearest Apple Store or Apple Authorized Service Provider to get it checked. Book an appointment on getsupport.apple.com or use the Apple Support app.