Correct me if I am wrong but (from Miracast wikipedia):
which means that TV creates a WiFi network and mobile connects to it. Hence your question concerning same Wi-Fi network is not applicable, because by nature both devices are the in the same network.
WiFi in Samsung Galaxy S5 works fine, as well as Access Point function. What do you suspect is malfunctionaing from hardware perspective?
I have tried the function with another S5 phone and it also fails. The probability that two phones have aquired the same hardware problem is low, hence I am not convinced that brining them for hardware inspection will help. Both are model SM-G800F running Android: 6.0.1 (Marshmallow) but different firmwares:
I wonder if Samsung Galaxy S5 is known to work with screen mirroring in early Sony Bravia TVs (year 2013) :