Certain mobs have a odd chance of dropping experience when killed by a golem. Zombie Pigmen are an example.
I think it has to do with if the player is holding a weapon.
I am providing a screenshot showing which zombie pigmen dropped XP.
I also noticed the XP was dropped by the only one that died of falling caused by the zombie being flipped.
I am unsure if this caused it, but I hit 1 of the pigmen, and that may caused it.
I tried it with zombies because zombies and Pig Zombies share a lot of AI and that doesn't seem to trigger it, so none from zombies
MC-56653 Zombified Piglins drop XP and rare drops if killed by anything while in angered state