pkgbuild productbuild requires admin privilege during pkg installation
I think you have more developer skills like me, in this particular case the SIP could be the reason for this. Try to log in as root. 

And it is stupid question: did you enable in System Preferences > Privacy > Allow apps downloads from  „anywhere“??  

Fastlane is an alternative for building pkg files.