This is related to Maxwell's first equation of electromagnetism, otherwise known as Gauss' law.
The equation representing Gauss' law is,
$\nabla \cdot \mathbf{E} =\frac{\rho}{\varepsilon_0}$
where $\mathbf{E}$ is the strength of the electric field, $\rho$ is the charge density and $\varepsilon_0$ is the permitivity of free space.
Now imagine constructing a sphere or radius $r$ that encapsulates all of the relevant charge. By integrating both sides over the volume of the sphere we obtain,
$\int\limits_{V}\nabla \cdot \mathbf{E} =\int\limits_{V}\frac{\rho}{\varepsilon_0}$
We can now apply the divergence theorem to the left hand side, and the right hand side turns out to just be the total charge enclosed in the sphere, divided by the permitivity of free space,
$\oint\limits_{S(V)}\mathbf{E} \cdot dS =\frac{Q}{\varepsilon_0}$
Now under the assumption of a spherically symmetric charge distribution within our constructed sphere, the value of $\mathbf{E}$ will be constant across the surface of the sphere. Therefore we can evaluate the LHS by simply multiplying $\mathbf{E}$ by the area of a sphere to give,
$4\mathbf{E} \pi r^2 =\frac{Q}{\varepsilon_0}$,
and thus,
$\mathbf{E} =\frac{Q}{4\pi\varepsilon_0r^2} = \frac{kQ}{r^2} = \frac{k\int dq}{r^2}$.
Therefore we can see that as long as the charge distribution within our constructed sphere is spherically symmetric such that $E$ is constant along the sphere, the actual distribution of the charge doesn't effect the calculated value of $E$. That is if the distribution of charge is all at the centre, of if it is all within a radius $r_0$ from the centre, as long the distribution is spherically symmetric, and the total charge is the same, then the electric field at some radius $r$ will be the same.