A flame makes plastic glueable
What a brief flame changes about a surface, and why printers use the same trick.
Passing an open flame briefly over a low-energy plastic like polypropylene burns oxygen-containing groups onto its outermost molecules, raising the surface energy of just that thin skin enough for glue and ink to wet it properly, without melting, warping or otherwise affecting the bulk of the plastic beneath.
The chemistry behind flame treatment
A plastic such as polypropylene resists gluing because its molecules are made almost entirely of carbon and hydrogen, arranged in long chains with nothing on their surface for a liquid, or a chemical bond, to grip onto strongly. A brief pass through the hot, oxygen-rich outer edge of a flame, of the kind produced by a Bunsen burner burning a premixed flame of fuel and air, supplies enough heat and enough available oxygen right at that instant to burn small amounts of oxygen directly onto the outermost layer of molecules, creating new chemical groups on the surface that are far more polar, and far more attractive to glue, ink or paint, than the untouched plastic underneath. The flame is only ever in contact with the surface for a fraction of a second, since holding it any longer would scorch or melt the plastic outright, but that fraction of a second is enough time for the surface chemistry to change while the bulk material, only a short distance beneath it, barely warms at all.
The marshmallow comparison
Toasting a marshmallow over a campfire flame shows how little heat actually penetrates during a brief exposure. The outside blackens and crisps within seconds, transformed by direct contact with the flame, while the centre, protected by the marshmallow's own bulk and by how little time the heat has had to travel inward, stays soft, pale and barely warmed at all. Pull the marshmallow away at the right moment and the contrast is obvious between a surface that has changed completely and an interior that has hardly changed at all, which is exactly the relationship between a flame-treated plastic's outermost few layers of molecules and everything sitting just beneath them, changed at the surface, essentially untouched a fraction of a millimetre down. Hold the flame in place too long, the same way leaving a marshmallow too close to the fire eventually catches the whole thing alight rather than just its skin, and the heat has time to travel further inward, softening or distorting the plastic underneath instead of merely treating its surface, which is exactly why the technique depends on a fast, brief pass rather than a lingering one.
Where this stops being true
Flame treatment changes only the plastic's own surface chemistry, so it cannot rescue a joint that is failing for some other reason entirely. A surface still carrying a film of release agent, oil or dust from handling will resist gluing just as stubbornly after flame treatment as before, since the flame is reacting with whatever sits directly on top of the plastic, and a layer of contamination simply intercepts the effect before it ever reaches the polymer itself. Some plastics also have little need for the treatment in the first place, since materials that already carry polar chemical groups on their surface, rather than the plain carbon-and-hydrogen chains of polypropylene and its close relatives, tend to have naturally higher surface energy and wet reasonably well without any surface treatment at all.
What follows from this
Because flame treatment only alters the surface, it needs to be done shortly before gluing or printing, since the newly reactive surface groups gradually lose their effect over time as they reorganise or pick up contamination from the air, and a part treated too long before it is used can end up little better than one never treated at all. The same principle scales up considerably beyond a workbench flame: plastic bottles and containers destined to carry printed labels or graphics are commonly passed through a brief flame, or an equivalent electrical treatment that achieves the same surface oxidation without an open flame, on a production line immediately before printing, precisely because the effect needs to be fresh to be reliable and cannot simply be applied once and stored indefinitely.