The energy of the particle is proportional to the oscillation frequency of its wavefunction, $E=h\nu$. A photon always moves at the speed $c$, so its wavelength is related to the frequency in the usual way for a traveling wave, $\lambda = c/\nu = hc/E$.
A massive particle moves more slowly than the photon, so its wavelength is shorter for the same amount of energy. Naively, we might guess that a particle moving at speed $v$ would have $\lambda = hv/E$ as its wavelength. This is not correct because it fails to account for relativity, but it may give you an idea of why the wavelength is shorter for a particle with mass.
To get the correct relationship, we need to consider the relativistic energy of the particle. According to special relativity, the energy is actually $E = \sqrt{p^2c^2 + m^2c^4}$. For a particle at rest, this is the famous $E=mc^2$. The kinetic energy is the difference between the total energy and the energy at rest (mass energy).
For a photon, all of the energy is kinetic because it has no mass. For a non-relativistic electron, with momentum $p \ll mc$, we can use a Taylor expansion to get an approximate expression for the kinetic energy.
\begin{align}
KE &= \sqrt{m^2c^4 + p^2c^2}-mc^2\\
&\approx mc^2\left(1+{1 \over 2}{p^2c^2 \over m^2c^4 }\right)-mc^2\\
&={p^2 \over 2m}
\end{align}
The DeBroglie wavelength is related to momentum by $\lambda =h/p$, and pluggin it in we obtain the formulas you asked about.
\begin{align}
E_{\mathrm{photon}} &= {hc \over \lambda}\\
E_\mathrm{electron} &= {h^2 \over 2m\lambda^2}
\end{align}