String routername = "Testing123";
wifi_station_set_hostname(routername.c_str());
I'm using the same method in my sketches, and it is working on my side.
So, maybe the problem is on the router side, maybe it have cache an kept the old name used before.
Try to power recycle the router to see if it help.