It is only there to prevent mechanical resonance, because if the core is too loose, it can cause ringing that some people can hear. Also, the core gap is very critical to the operation of a flyback transformer, so the glue helps prevent the core from moving too much and causing the core gap to shift.