This was probably covered, but I only just found out how to get 5.1 surround from my PS4 via optical cable when watching Blu-ray movies. Which needless to say wasn't working out of the box. And unsurprisingly, the setting was inexplicably hidden deep in the Blu-ray settings. Not in the System settings but in the Settings you can access while watching the movie itself.
Madness, I tell ya!!
So if you're trying to get 5.1 DTS or DD through optical cable while watching Blu-ray movies but are unable to, and too embarrassed to ask why and how to fix it, good news! You are not alone! And your PS4 is not broken.