I don't know how Maxwell derived it, or even
whether he derived it. But there are two things I can say about where the result comes from.
First, you can show as a result of the Special Theory of Relativity that the general expression for the energy, E, of a particle is given by:
E2 = p2c2 + m2c4
where p is the momentum of the particle, m is its mass, and c is the speed of light. So, for a massless (m = 0) particle like a photon, this reduces to
E = pc
Second, this result is not inconsistent with the results of quantum mechanics. For example, quantum mechanics says that for particle states in which there is a definite momentum, that momentum is given by
p = \hbar k
where \hbar is h/2π, h is Planck's constant, and k = 2π/λ is the wavenumber of the particle. However, you may also be familiar with the result from quantum mechanics that the photon energy is given by:
E = hν
where ν is the frequency of the photon. Now, remember that the relationship between frequency and angular frequency (ω) is ν = ω/2π. So we can write the photon energy as:
E = (hω)/2π = \hbar \omega
I apologize for the hybrid between LaTeX and non-LaTeX equations. I couldn't be sure that hbar character would show up for all users, so I resorted to LaTeX to generate it. Anyway, so we have the results that:
p = \hbar k and E = \hbar \omega. How are ω and k related? Well, recall that the speed of a wave is the product of its wavelength and its frequency:
c = λν = (λω)/2π = ω/k
Therefore:
ω = kc
and:
E = \hbar \omega = \hbar kc = pc
Same result.