Based on the evidence I suspect that the compiled code (it’s a special form after all) sanitizes the value returned from the function by forcing the __struct__ value to reflect the primary module - but that is just a guess.
I doubt it’s a bug. For example the Access Behavior makes use of that __struct__ value to access the structure specific implementations for navigation and access. If __struct__ was left at XX you would automatically “inherit” all the XX functionality but have no way of overriding it for YY.
I suspect the bug is with Kernel.struct!/2, not Kernel.SpecialForms.%/2.
As you discovered, it only presents when you start defdelegating the constructor and I don’t think this code anticipated that.
So the question is - what are you trying to accomplish by defdelegating the struct constructor to another struct? Sharing code between XX and YY should probably be accomplished via a shared third module.