Very weird these ESP issues, and I've faced similar of them in past, each having its own even weirder workarounds. Hope this helps someone:
This time, I put a sleep in my code as so (I'm using micropython):
macaddress = ubinascii.hexlify(ap_if.config('mac'),':').decode()
macaddress = macaddress.replace(':','')
ap_if.config(essid="ABC1_"+macaddress, password="ZYXDFWER")
# Fix added recently : Added 3 sleeps of 0.5 sec each
utime.sleep_ms(500)
utime.sleep_ms(500)
utime.sleep_ms(500)
ap_if.ifconfig(('192.168.0.1', '255.255.255.0', '192.168.0.1', '192.168.0.1'))
And now, every thing (at least so far) seems to work.
I've no explanation for why that would happen, but it may be possible that DHCP settings in last line do not take effect until the ssid configuration is complete, and that may require some things which happen after that line executes. So may be sufficient sleep ensured those things finished, and then DHCP settings work.
I'm just guessing. Anyone who has more idea, I request to share their pearls of wisdom. This unfortunately is beyond my domain of expertise, seeking someone who has had similar issues.
EDIT 1:
The issue was not fixed, and still happens :( Apparently power supply issue? I'm going to use USB on the 'yu robot' and try again, and let you guys know the result.
EDIT 2:
The issue seems to be that I've not put 470uF cap where I need it, that is, its needed across 3.3V power, whereas I'd put it at the 12V power. I put the cap across yu robot's 3.3V output (lower right part has a +/- where I put the cap) and things have been stable so far. No reboots, but i've done that just 8-10 times. I'll keep doing and let you know after some 100 attempts over next week or so.