“Especially when screen locks” is by design. All iPhones from the beginning of iPhone time 17 years ago disconnect from Wi-Fi 30 seconds after the phone screen locks, to preserve battery energy, unless the phone is connected to power. This is done because a Wi-Fi connection uses power continuously, whether data are transferring or not. Cellular connections use more energy, but only when actually sending data. There are a few exceptions:
- If you are streaming audio or video Wi-Fi will stay on
- If you receive a notification Wi-Fi will reconnect for a few seconds to process the notification
- And, I think (but I’m not sure) if an app uses Background App Refresh it can wake and use Wi-Fi; however very few apps actually use Background App Refresh.