Apple documents the order in which a network will be joined in instances where the iOS device is rebooted and not unlocked as well as when the device is running normally at https://support.apple.com/en-us/HT202831
In specific, to quote the article:
iOS will try to connect to networks in this order:
- The private network it most recently joined
- A private network
- A hotspot network
If iOS finds more than one network, it evaluates SSIDs by security level and chooses one based on the following order:
- Private network: EAP
- Private network: WPAWPA3
- Private network: WPA2/WPA
- Private network: WEP
- Private network: Unsecure/open
- Hotspot network: HS2.0/Passpoint
- Hotspot network: EAP
- Hotspot network: WPA
- Hotspot network: WEP
- Hotspot network: Unsecure/open
If iOS finds multiple networks of identical type and security level, it chooses the SSID with the strongest RSSI.
Once you know this, you can sometimes choose the settings on your preferred network or refrain from auto-joining some SSID that you know will cause your device to choose a less preferred (to you) network than the system is designed above. As a last resort - being physically closer to your preferred network would raise the RSSI - signal strength in case your device is set up for that to be the tie breaker when it has to choose between two otherwise "equal" networks.
--
A lot of comments and answers are also about roaming - so if that's your concern, check out the 802.11r FT / Adaptive 802.11r / 802.11k and 802.11v enhancements for roaming in this white paper by Cisco that is designed to take advantage of all of Apple's roaming implementations.
Roaming is for when you have more than one base station broadcasting the same SSID and you will need to properly place the transmitters so there is overlap between the handful (ideally) of radios and adequate coverage that the device can talk to both base stations when in the middle to make an orderly transition.