The idea is that you want to initialize the weights in a way that ensures good forward and backward data flow through the network. That is, you don't want the activations to be consistently shrinking or increasing as you progress through the network.
This image shows the activations of a 5 layer ReLU Multi-Layer Perceptron under 3 different initialization strategies after one pass of MNIST through the network.

In all three cases weights are drawn from a zero-centered normal distribution which is determined by its standard deviation. You can see that if the initial weights are too small (the standard deviation is small) the activations get choked, and that if they are too large the activations explode. The middle value, that is approximately right can be found by setting the weights such that the variance of the activations and gradient updates stays approximately the same as you pass through the network.
I wrote a blog post about weight initialization that goes into more detail, but the basic idea is as follows.
If $x^{(i)}$ denotes the activations of the $i$-th layer, $n_i$ the size of the layer, and $w^{(i)}$ the weights connecting them to the $(i+1)$-st layer, then one can show that for activation functions $f$ with $f'(s) \approx 1$ we have
$$
\text{Var}(x^{(i+1)}) = n_i \text{Var}(x^{(i)}) \text{Var}(w^{(i)})
$$
In order to achieve $\text{Var}(x^{(i+1)}) = \text{Var}(x^{(i)})$ we therefore have to impose the condition
$$
\text{Var}( w^{(i)}) = \frac{1}{n_i}\,.
$$
If we denote $\frac{\partial L}{\partial x_j^{(i)}}$ by $\Delta_j^{(i)}$, on the backward pass we similarly want
$$
\text{Var}(\Delta^{(i)} ) = n_{i+1} \text{Var}(\Delta^{(i+1)}) \text{Var}(w^{(i)})\,.
$$
Unless $n_i = n_{i+1}$, we have to compromise between these two conditions, and a reasonable choice is the harmonic mean
$$
\text{Var}(w^{(i)}) = \frac{2}{n_i+n_{i+1}}\,.
$$
If we sample weights from a normal distribution $N(0, \sigma) $ we satisfy this condition with $\sigma = \sqrt{\frac{2}{n_i + n_{i+1}}} $.
For a uniform distribution $U(-a, a) $ we should take $a = \sqrt{\frac{6}{n_i+n_{i+1}}} $ since $\text{Var} \left( U(-a,a) \right) = a^2/3 $.
We have thus arrived at Glorot initialization. This is the default initialization strategy for dense and 2D convolution layers in Keras, for instance.
Glorot initialization works pretty well for trivial and $ \tanh $ activations, but doesn't do as well for $ \text{ReLU} $.
Luckily, since $ f(s) = \text{ReLU}(s) $ just zeroes out negative inputs, it roughly removes half the variance and this is easily amended by multiplying one of our conditions above by two:
$$
\text{Var}(w^{(i)}) = \frac{2}{n_i}\,.
$$