When you heat the copper wire in a flame, it is oxidized on the surface to copper (II) oxide:
$$\ce{2Cu(s) + O2(g) -> 2CuO(s)}$$
Then when you mix it with the halide and heat it, the halide's higher electronegativityreduction potential makes it displace the oxygen.
Here's an example with sodium chloride:
$$\ce{CuO(s) + 2NaCl(s) -> CuCl2(g) + Na2O}$$
Copper halides are volatile (except for fluorides); the gas is hot enough to push some electrons into an excited state, and as they cool a tiny bit, the electrons drop back into their rest state and emit the excess energy in the form of a photon with a wavelength corresponding to the color green.