Try using the WiFi in the phone as close as possible to your home network router i.e. <15cm and check if it detects, connects and maintains a stable connection.
If it does, mostly likely it is a problem with the antenna - loose connection or faulty.
Here's a previous answer in ifixit that details how to remove/replace the antenna in the phone.