iPhone not registering bluetooth keyboard keystrokes
Given that your iPhone and keyboard connect and work just fine when the iPhone is connected to non-public WiFi networks, most likely the public WiFi networks are using frequencies that interfere with the Bluetooth in the keyboard. I would guess that by powering cycling your iPhone, it renegotiates the Bluetooth frequencies with the keyboard which do not interfere. Other factors at work may be microwave ovens, wireless speakers, Dish satellite systems, power sources, badly shielded cables &amp; wires, and a host of other causes. Apple has a great rundown of things that can cause interference. 

https://support.apple.com/en-us/HT20154

We live in a world saturated with radio and microwave radiation. If the poor public Wi-Fi locations are in locations where there are other people with phones, Bluetooth devices, etc, I’m not surprised that things don’t work well sometimes.