In your iPhone’s settings, go to “Wi-Fi,” and ensure “Ask to Join Networks” is set to “Ask,” and that “Auto-Join Hotspot” is set to “Ask to Join.” This will stop your iPhone connecting to new or known networks or personal hotspots without you realizing, giving you the opportunity to exercise caution before clicking “Yes.”

Settings / Wi-Fi

Much more importantly, you should click on the blue-circled “i” next to any public network you connect to, and disable the “Auto-Join” option. You don’t need to click on “Forget This Network,” but you can do that if you’re unlikely to be back. This way you control where and when your iPhone connects. 

Settings / Wi-Fi