iPhone 7 Plus randomly wouldn’t let me do things?
Being unable to hear through the speaker and the speakerphone button being grayed out are symptoms of a hardware failure with the device.  The troubleshooting you could try is: 


Force restarting the device - Do this by holding the power button and the down volume button together for ~10 seconds.  When you see the Apple symbol let go of the buttons. Then test to see if it's working.
Reset settings - Under Settings> General> Reset, select 'Reset All Settings'.  After the reset test to see if it's working.
Perform a restore - Backup you device before doing this step using iCloud or iTunes. 
Best way to do restore is by connecting to a computer with iTunes, then performing the force restart steps, holding the buttons slightly longer until you see the iTunes symbol show on the iPhone screen.  Then follow the prompts in iTunes.  Once restore is complete setup as new if possible then test again to determine if issue is still happening.


Since your device is still under warranty I recommend contacting Apple Support.  They will make sure you have completed all necessary steps and if the issue is still occurring be able to present you with replacement options.