Hi,
I don't know why this problem happen, pin PG4 seem that have no special.
I think it maybe cause by other reason, such as external interference signal. If you check CKOPT and BODEN fuse bits
And you may try use other pin to launch bootloader, to see whether same problem may happen.
If you have do more test, please tell me the result.