Here's the reason for it.
When, any atom gets heated, some electrons get excited to the higher energy state. As the excited electrons return to their ground state, they emit photons of very specific energy. This energy corresponds to particular wavelengths of light, and so produces particular colors of light.
If the energy released falls in the visible light spectrum of the electromagnetic spectrum, colour is observed.
For knowledge, copper produces a blue flame , lithium and strontium a red flame , calcium an orange flame , sodium a yellow flame , and barium a green flame.
Here's a video on it:
Hope it Helps :)