Derivation (stationary state in 1D infinite potential well)
Schrodinger's equation is $$ \begin{align*} -\frac{\hbar^2}{2m} \dfd[2]{\chi}{x} + U(x) \chi = E\chi. \end{align*} $$
Outside the well ($x<0$ or $x>a$), since $U(x) = \infty$, we must have $\chi(x)=0$.
Inside the well ($0<x<a$), the equation becomes $$ \begin{align*} \dfd[2]{\chi}{x} + \frac{2mE}{\hbar^2} \chi = 0 \end{align*} $$ which has a general solution $$ \begin{align*} \chi(x) = A \sin (kx) + B\cos(kx), \quad \text{ where } k=\frac{\sqrt{2m E}}{\hbar}. \end{align*} $$
Since $\chi$ is continuous, we need $\chi(0) = 0 = \chi(a)$. Therefore $$ \begin{align*} \chi(x) = A\sin(kx), \qquad k=\frac{n\pi}{a}, \qquad n=1,2,3,\ldots. \end{align*} $$ Hence the energy is quantised as $$ \begin{align*} E = E_n = \frac{\hbar^2\pi^2}{2ma^2} n^2. \end{align*} $$
Applying the normalisation condition, $$ \begin{align*} 1 ={}& \int_{-\infty}^{\infty} |\chi|^2 \d x \\ ={}& \int_{0}^{a} |A|^2\sin^2(kx) \d x \\ ={}& \frac{a}{2} |A|^2 \\ A ={}& \sqrt{\frac{2}{a}}. \end{align*} $$