Just as an addition: I stumpled across the same (plus another problem) while upgrading my nexus 5 from Lollipop to Marshmallow. Every time when the phone was at sleep mode (for example: while driving my car and phone rested in the pocket) and I walked into a know wifi it did not auto connect.
Usually when I arrived at work, as soon as I exited at the parking lot I got notified for incoming mails or messages, but not anymore on Android 6. As soon as I unlocked the phone wifi automatically connected and everything was fine. But I always forget to do this and It sometimes took hours before I realized I haven't done this step and messages won't get sent to me since I was not connected to the wifi until I picked up the phone from the pocket and unlocked it once.
I looked through all the settings and policy stuff, and finally I found something that worked:
Under Settings -> Power -> ... -> Power Optimimization you can switch the list from "unoptimized apps" to "all apps". Then search for "Google Connectivity Services" and disable the power optimisation for this system app.
After I've done it finally autoconnects to known wifis while my phone is in my pocket.
UPDATE I just wanted to leave a note, that there was a small update a couple of days/weeks ago that brought back the not autoconnect issue to me, Power Optimization did not work for me anymore. Still have this issue, I will do a clean Android 6 install in the next weeks and look if the issue still exists. If yes I will stick with Android 5.x
UPDATE2 There was another update a while ago that almost "fixed" this problem.