The only way I’ve managed to avoid my iPhone connecting to random wifi is to go to settings:wifi and set “ask to join” to true. And now it just bugs me with prompts a hundred times every train ride.
Ifaik there’s no other way to stop autoconnecting to wifi that matches certain conditions, and it drives me up the wall.