I had similar problem where connecting to the wifi network worked only after a first few deep sleep cycles (or even didn't work at all) and after adding forceSleepWake()
...
WiFi.persistent(false); // <-- prevents flash wearing?
WiFi.forceSleepWake(); // <-- WITHOUT THIS ESP CONNECTS ONLY AFTER FIRST FEW RESTARTS OR DOESN'T CONNECT AT ALL
WiFi.begin(ssid, password);
WiFi.config(ip, gateway, subnet);
...
everything started to work as expected. Here I described everything in more details.
I don't know if newer libraries solved the problem becouse I am still using the same code that I know always works.