The bug
If you kill a wandering trader while it is drinking an invisibility potion or a milk bucket, it has an 8.5% chance to drop the held item. (The chance increases with the looting enchantment.)
To reproduce
/give @p minecraft:emerald{Enchantments:[{lvl:255s,id:"minecraft:looting"},{lvl:255s,id:"minecraft:sharpness"}]}
/time set night
/summon minecraft:wandering_trader
Punch the wandering trader with the emerald while it is drinking the invisibility potion. The invisibility potion is dropped when the wandering trader dies. ❌
/summon minecraft:wandering_trader
Wait for the new wandering trader to become invisible.
/time set day
Punch the wandering trader with the emerald while it is drinking the milk bucket. The milk bucket is dropped when the wandering trader dies. ❌
I originally expected both MC-229441 and the behavior described in this report to be intended. Since Mojang decided that MC-229441 was not intended, I decided to report this behavior so that Mojang can decide whether or not this behavior is intended. I'm not very knowledgeable about the spawning mechanics of wandering traders, but it seems plausible that the behavior described in this report could be used to create an AFKable invisibility potion farm. (The farm would be very slow, though.)