Speaker Icon grayed out and sound doesn't work
Thank you for displaying the audio output settings in System Preferences.
This is very likely physical issue with your MacBook Pro (MBP). Your MBP supports three outputs:

speakers
headphone jack
optical/digital output (using your headphone jack)

When the optical output is activate there is no way to change it to speakers using a macOS setting. As this output doesn't support volume changes your speaker icon is grayed out.
Please check with a flashlight if there is something stuck in your MBP's headphone jack (debris, dust or similar). The optical output setting is triggered using a physical
Carefully try to remove it with a toothpick.

Please report back if you

can see a red light coming out of the headphone jack when playing a song
could solve the issue with a toothpick
used wired headphone with your MBP in the last few weeks.

edit:
I've taken a picture to show how the port can determine whether it's a headphone plug or an optical cable. The optical cable is just a tad longer and triggers the optical output in macOS.: