It is perhaps a question of semantics, to some extent, but you can't talk about the energy of a quantum particle unless it is in a state of definite energy i.e. an eigenstate of the Hamiltonian. If you had a superposition of two energy eigenstates, say $$|\psi\rangle = c_1 |E_1\rangle + c_2 |E_2\rangle,$$ any measurement of the energy will result in either the state collapsing to the state $|E_1\rangle$ or $|E_2\rangle$, with the resulting energy being $E_1$ or $E_2$ respectively. The probability that an energy $E_1$ will be measured is thus $|c_1|^2$, and that an energy $E_2$ will be measured is $|c_2|^2$. So speaking of the "energy" of the state $|\psi\rangle$ doesn't make sense.
One can, of course, speak of the expectation value of the energy in the state $|\psi\rangle$: $$\langle E\rangle = \langle \psi | \hat{H}|\psi \rangle.$$
This quantity is well defined, and can take a range of values, but isn't the same thing as the "energy" of the state.
Note: Nothing about this is unique to the Hamiltonian. It is not sensible to speak of the "value" of momentum of a quantum state if it isn't in a state of definite momentum (i.e. an eigenstate of $\hat{p}$) and so on for any quantum observable. However, you could always speak of the expectation values of these observables, though its interpretation is different.
Edit: As mentioned in the comments, I interpreted the OP's question as follows: why is it that the only energies that a particle in a box is allowed to be in are the eigenvalues of the time-independent Schrodinger equation. I feel that the OP clearly understands why the energy restrictions apply to the time-independent Schrodinger Equation, just not why are arbitrary state cannot be said to have some fixed energy.
That being said, @BioPhysicist raises a fair point: my argument does not explain why these energies have to be discrete. Indeed, in general, they do not. There are two classes of solutions to the Schrodinger Equation, solutions that have a discrete spectrum ("Bound states") and solutions that have a continuous spectrum ("Scattering states"). If a particular potential allows for scattering states (as, for example, the finite potential well, these solutions will not have discretely spaced energies. Nevertheless, the only states in which the "energy" of the particle can be spoken of in any meaningful way still remain the eigenstates of the Hamiltonian.
In general, a good guess as to whether or not a potential admits scattering states can be made by looking at the behaviour of the potential at infinity. Scattering states are -- crudely -- states where at the particle "starts off" as a free particle at $x = -\infty$, and ends up as a free particle at $x = +\infty$. For certain potentials (like the infinite potential well and the harmonic oscillator) the "strength" of the potential keeps increasing as we go further away, and therefore the particle never has the possibility of being "free". Such potentials only admit bound (and therefore discrete) state solutions.
I would not blame you if you didn't find the above analysis convincing, but I cannot think of an "intuitive" reason for the existence of discrete energies for the infinite potential well.
Further reading: What exactly is a bound state and why does it have negative energy? and Bound states, scattering states and infinite potentials.