In your phone settings...Settings/Wi-Fi...click the gear icon...Keep Wi-Fi on during sleep...Always.
This is from my Nexus 5X, should be the same path as yours.
Was a fix ever found for this? I am having the same trouble with my TCL Roku TV.
I thought it was probably my battery optimization settings, but I changed those and the problem still continues.