Until 1905, the light considered to be an electromagnetic wave, as suggested by Maxwell. Hence, the light possesses all the properties of a wave. He also showed that the speed of light in a vacuum given by

which is equal to the speed of light in a vacuum (c).
In the era of Einstein’s five years of miracle, he used Planck’s idea of quantization of the energy and proposed, “the photoelectric effect could be understood, if the light was quantized in the form of some wave packets called photons and not in the form of waves.” This idea gave rise to the concept of photons.
Photons are the mass-less energy packets that move with the speed of light in a vacuum (2.998 x 10^8 m/s). Photons are said to possess the energy equal to the integral multiple of frequency times Planck’s constant.
E = hv
“But the question comes here is from where do the photons get this much energy?” To find the answer, let’s go to Einstein’s mass-energy equivalence from a relativistic perspective.
The energy is given as
E^2 = m^2 * c^4 + p^2 * c^2
indicates that the total energy is the sum of the mass-energy and the momentum-energy. The momentum here can be related to mass or not.
The momentum is not limited to p = mv. In Newtonian mechanics, this holds correct, but in the case of waves and relativistic mechanics, this expression is not enough to explain the momentum of the object.
“Momentum is the property of the object in motion, which acts directional and describes the capability of influence on the other object.” It has nothing to do with mass.
Applying this equation to the photons, we know that photons are mass-less particles. That means, the mass m = 0 for photons. Therefore, the mass-energy will be zero in this case. Now, the energy entirely depends upon the momentum energy.
“Can you think of the fact that a particle that has no mass still exists?” Well, in the case of classical mechanics, the answer is- definitely not. There is no existence of a particle without any mass. Since we are talking relativistic mechanics, the mass-less particles can exist, if it travels with the speed of light.
The relativistic momentum, given by

Therefore, for velocity equal to the speed of light, the momentum comes out to be in the form of 0/0 form, which is indeterminate. That means the momentum will have some value other than zero. Since the momentum is related to energy, the energy will also have some value.
Thus, we can say that for a mass-less particle moving with the speed of light, the momentum will be a non-zero quantity. Hence, it will have some momentum-energy with it. Now talking about Einstein’s & Planck’s idea of seeing the light, consisting of photons, the energy of the photons was given as
E = hv
Also, the relation between frequency and the wavelength is v = c/lambda. Therefore, using this relation in the above expression, the energy comes out to be E = pc.
This is what we want to emphasize that the energy of the photons is due to the momentum of the photons. We know that the light has wave-particle duality, which means that light posses all the properties of both the wave and the particle. The wave with no mass also transforms the momentum. So, the photons have momentum, and the momentum gives rise to energy. Therefore, the photons get energy from their momentum.
“I like to conclude the entire discussion by saying that the photons get their energy from their relativistic momentum because they travel with the speed of light, irrespective of being mass-less, and have wave properties.”