Momentum of a photon equals Planck's constant over wavelength A common identity in Quantum Mechanics is relation between the momentum of a photon and its wavelength:
$$p = \frac{h}{\lambda}$$
The identity is discussed here, for example:
https://en.wikipedia.org/wiki/Matter_wave
Apparently, this is the identity rearranged by de Broglie to give the wavelength of the wave nature of a particle. But where does this identity come from in the first place? I have seen some quite "hand-wavy" ways of deriving this using $E=mc^2$, but it seems quite strange having to rely on relativity to obtain this identity. Or is it exactly what we must do? This seems to be a quite fundamental identity in Quantum Mechanics, so I would like to understand its justification as well as possible. I've been told that light having momentum is an idea present in classical mechanics as well and was known much before quantization of light and photons were discovered.
 A: It seems like your are not satisfied by answers involving axioms. I think that you instead want to know the motivation behind the axiom beyond just saying that it works. I am not sure if my answer is the original motivation, but I think it can be viewed as a good motivation for the validity of $p= \frac{h}{\lambda}$. While other answers do a great job at going into the theory, I will tackle the question using more of an experimental motivation. 
We will first start with the double slit experiment. This experiment is usually first introduced as evidence of the wave-like nature of light, where light emanating from one slit interferes with light emanating from the other (of course a different interpretation is found if we send single photons through the slits and the same interference pattern arises, but I digress). However, this experiment also works with electrons. You get an interference pattern consistent with treating the electrons as waves with wavelength 
$$\lambda=\frac hp$$
You get maxima in intensity such that
$$\sin\theta_n=\frac{n\lambda}{d}$$
Where $\theta$ is the angle formed by the central maximum, the slit, and the maximum in question, $d$ is the slit separation, and $n$ is an integer.
This would then be a way to experimentally motivate/verify this relationship between momentum and wavelength for matter, but what about photons? The double slit experiment does not give us a way to validate $p=\frac h\lambda$ (that I know of. Maybe you could determine the radiation pressure on the detector?). Let's look at a different experiment.
We know that the energy of a photon from special relativity is 
$$E=pc$$
So, if our momentum relation is true, it must be that
$$E=\frac{hc}{\lambda}=hf$$
which is something that can be verified experimentally to be true. The photoelectric effect is one such experiment we could do, where shining light onto a material causes electrons or other charge carriers to become emitted from that material. The higher the frequency of the light, the more energetic the electrons coming from the material are, and the maximum kinetic energy of an electron can be shown to follow $K_{max}=h(f-f_0)$ where $f$ is the frequency of the light and $f_0$ is the material-dependent threshold frequency (i.e. we need $f>f_0$).
I know that my answer does not get to a fundamental explanation of this relation in question, but I hope it shows why one would want it to be a fundamental idea that holds true when formulating QM. If you want a more fundamental explanation, then I will edit or remove this answer due to some pretty good fundamental answers already here.
A: Glossing over lots of subtleties:
A fundamental axiom of quantum mechanics is the canonical commutation relation $[\hat{X}, \hat{P}] = i \hbar$. In this position basis, this becomes $\hat{X} \to x$ and $\hat{P} \to -i \hbar \frac{\partial}{\partial x}$ (modulo lots of technical details involving the Stone-von Neumann theorem, etc.).
Another fundamental axiom of quantum mechanics is that states with definite values of a physical observable must be eigenstates of the corresponding Hermitian operator. So a particle with momentum $p$ is described by a wave function $|p\rangle$ satisfying $\hat{P} |p\rangle = p |p\rangle$. (Whether we can legitimately talk about the wavefunction of a massless relativistic particle is another subtlety that I'll gloss over.)
Putting this together, we have that in the position basis
$$-i \hbar \frac{\partial \psi}{\partial x} = p \psi(x) \implies \psi(x) \propto e^{i p x / \hbar}.$$
So the wavefunction is spatially periodic with period $\lambda = 2 \pi \hbar / p = h / p$, so $p = h / \lambda$. This "derivation" works equally well whether or not the particle is massive or massless.
A: I'll build on tparker's answer in a way that emphasizes the great generality of the relationship between momentum and wavelength.
In classical physics, a very general result called Noether's theorem can be used as the foundation for a definition of momentum. The inputs to Noether's theorem are:


*

*the action principle — loosely translated, this says that if one physical entity influences another, then they must both influence each other;

*any continuous symmetry — such as rotational symmetry or time-translation symmetry.


Noether's theorem says that these inputs imply the existence of a conservation law associated with the given symmetry.  For example, rotational symmetry leads to the conservation of angular momentum, and time-translation symmetry leads to the conservation of energy. These connections may be regarded as the definitions of angular momentum and of energy, respectively.
If the symmetry is symmetry under translations in space, meaning roughly that the laws of physics are the same in all places, then the resulting conservation law is the conservation of momentum — that is, the total momentum of the system.  This connection may be regarded as the definition of momentum. 
In a model that includes the electromagnetic field, this definition of momentum includes a contribution from the electromagnetic field — and from anything else that participates in the action principle by influencing (and being influenced by) other entities.
In quantum physics, these same general connections come with another twist: for each of these symmetries, we have an operator that generates those symmetries (more detail given below), and this operator is quantum theory's representation of the corresponding conserved quantity.  In particular, the momentum operator generates translations in space. More precisely, this is the total momentum operator, which generates translations of the whole physical system in space. This operator is a basic ingredient in any quantum system whose laws are the same in all places.  This is true in both non-relativistic quantum mechanics and in relativistic quantum field theory.  Although the concept of a massless particle does involve relativity, the connection between momentum and space-translation symmetry does not rely on relativity.
Now, as promised, here's more detail about what it means to say that the momentum operator "generates translations in space."  As in tparker's answer, let $\hat P$ denote any single component of the momentum operator, which generates translations in that one direction in space. The answer by tparker already illustrated this nicely in the case of single-particle quantum mechanics. For another example, I'll consider how a massless photon is described in the quantum model of the electromagnetic field. In this model, instead of having an operator $\hat X$ for the position of a single particle, we have field-operators like $\hat E(x)$ and $\hat B(x)$ representing the electric and magnetic fields. These operators parameterized by the location $x$ in space. I'm omitting their vector indices to avoid cluttering the equations.
Now, a photon is a particle that, mathematically, is created by applying an appropriate linear combination of $\hat E(x)$ and $\hat B(x)$ to the vacuum state. Such a single-photon state may be written in the form
$$
  |1\rangle = \int dx\ \big(f(x)\hat E(x) + g(x) \hat B(x)\big)|0\rangle
$$
where $|0\rangle$ is the vacuum state and where $f$ and $g$ are appropriate complex-valued functions of the spatial coordinate $x$.  Given any such single-photon state, we can translate the photon in space by an amount $a$ by applying the operator $\exp(i\hat P a/\hbar)$, like this:
\begin{align*}
  \exp\big(i\hat P a/\hbar\big)|1\rangle
&=
\int dx\ \big(f(x)\hat E(x+a) + g(x) \hat B(x+a)\big)|0\rangle
\\
&=
\int dx\ \big(f(x-a)\hat E(x) + g(x-a) \hat B(x)\big)|0\rangle.
\end{align*}
The second step follows simply by changing the integration variable.
The first step follows from 
\begin{align*}
  \exp\big(i\hat P a/\hbar\big)\hat E(x)
  &= \hat E(x+a)\exp\big(i\hat P a/\hbar\big)
\\
  \exp\big(i\hat P a/\hbar\big)\hat B(x)
  &= \hat B(x+a)\exp\big(i\hat P a/\hbar\big)
\end{align*}
which is what it means to say that $\hat P$ generates translations, together with 
$$
  \hat P\,|0\rangle = 0
\hskip1cm
\Rightarrow
\hskip1cm
  \exp\big(i\hat P a/\hbar\big)\,|0\rangle = |0\rangle,
$$
which says that the vacuum state is invariant under translations.
Since $\hat P$ is also the momentum operator by definition (as in the Noether's-theorem perspective described above), saying that a photon has a single momentum $p$ is equivalent to saying that the state $|1\rangle$ satisfies
$$
  \hat P\,|1\rangle = p\,|1\rangle.
$$
(By the way, the other equation $\hat P\,|0\rangle=0$ shown above says that the vacuum state has zero momentum.)
This implies
$$
     \exp\big(i\hat P a/\hbar\big)\,|1\rangle
 = \exp\big(i p a/\hbar\big)\,|1\rangle.
$$
By itself, this is inconclusive, because in a single-photon state, there is nothing else for the photon to interact with that could reveal its wavelength.  However, the same principles still apply when we consider a photon in the context of some kind of interferometer, and then the fact that the photon's phase oscillates like $ \exp(i p a/\hbar)$ has observable consequences. In particular,  translating the photon through a distance $a$ such that $pa/\hbar = 2\pi$ is the same as multiplying its state by $\exp(2\pi i)=1$. In other words, its wavelength is 
$$
\lambda=2\pi\frac{\hbar}{p} = \frac{h}{p}.
$$
Although the idea of a massless photon does rely on relativity, the idea that the momentum and wavelength of a particle are related in this way does not. This relationship follows from the very general fact that the momentum operator generates translations in space — illustrated here using a model of the elecromagnetic field, and illustrated by tparker using single-particle quantum mechanics.
A: For convenience, let $k=2\pi/\lambda$ and $\omega=2\pi f$. Here $k$ is called the wavevector and $\omega$ is a version of the frequency that is in units of radians per second rather than oscillations per second.
Then we have the following two completely analogous relationships:
$$p=\hbar k $$
$$E=\hbar \omega .$$
The analogy holds because in relativity, momentum is to space as energy is to time.
If you assume $p=\hbar k$, then there are straightforward arguments that lead to $E=\hbar \omega$. If you assume $E=\hbar \omega$, there are similar aguments that get you to $p=\hbar k$. They're not independent of each other. If you believe in one, and you believe in relativity, then you have to believe in the other.
These are fundamental relationships that hold true in all of quantum mechanics. They're not just true for photons, they're true for electrons and baseballs.
With "why" questions like this, you have to decide what you want to take as a fundamental assumption. There are treatments of quantum mechanics that take various sets of axioms. Depending on what set of axioms you choose, these relations could be derived or they could be axioms. If someone tells you they have a proof of one of these relationships, you should ask them what assumptions they started from, and then ask yourself whether you find the assumptions more solid than these relations. Are the assumptions more intuitively reasonable? Better verified by experiment? Aesthetically preferable?
A: Ok, this is not a real direct answer to the question, but just a reaction to one of OP's comments. My remark was too long to fit in a comment, so I put it in an answer, sorry for that.
 S. rotos said he had a problem with one of the answers because : "yes, there are certain things that are axioms and not really derived so to speak, but there still must be some kind of intuition or justification. They don't just appear out of nowhere"
But I believe, they  sometimes (often ?) do ! 
Actually, if we follow the historical train of thought on this matter, we should remember Planck who was working to solve the UV catastrophe. He was desperatly trying to describe black-body radiation through statistical mechanics. Out of idea, he tried out the hypothesis that radiations were emitted in discrete bundles of energy E=hf. An idea that came (almost) straight up out of nowhere, as he admitted himself (at least, with absolutely no physical justification behind). He did not credit any physical meaning to it and considered it as mere mathematical trickery. 
Einstein, acknowledging how well Planck's result was describing the experimental results, later declared that there was indeed a physical meaning in all this. He interpreted it as the statement that light could also behave as a discrete particle with a given energy. Many consider this idea to be the beginning of quantum mechanics. De Broglie later took back this idea and mirrored it : he said that if a "wave" such as light could be described as a "particle" then a "particle" like an electron could be described as a "wave". This equivalence is done through the famous relationship we are talking about, and that can be considered as a natural consequence of the E=hf relation, as it has been explained in another answer
So as you see, we can pretty well say that the hypothesis "E=hf" did come out of nowhere ! Definitely not an intuitive statement : it went against all intuitions of that time. Just an hypothesis that was working so damn well that we tried to put some sense into it... And came up with quantum mechanics. I believe it is something that you have to take first as a mathematical trick, later confirmed by experimental fact. 
Trying to find an intuitive principle for something that, in its very core, is as counter-intuitive as QM is, imo, a desperate attempt. All those "paradoxes" and insane behaviours at the quantum scale have to come from something that is at least a little bit fucked up, wouldn't you agree ?
The idea that physics should be intuitive is something I generally disagree with. If it was, we would live on a flat earth, with a sun circling all around. That's intuition right there :D
