Neutrons can decay into protons inside the nucleus, via the reaction
$$
n \to p^+ + e^- + \bar{\nu}
$$
(i.e., beta decay). What's more, neutrons and protons are fermions, meaning we can only have one of them in a given quantum state. So we can think of the neutrons and the protons in a nucleus as "filling up" the available energy states up to some maximum energy level for each type of particle.
However, if a nucleus has a large number of neutrons relative to the number of protons, then the highest occupied neutron energy level will be higher than the highest occupied proton energy level. If that's the case, then the nucleus can shed energy by converting a neutron into a proton, since the daughter proton can occupy a lower energy level than the parent neutron. So it will do this and release energy in the process. Only if the highest occupied levels for the protons and neutrons are relatively close in energy will the nucleus be stable against this decay.
The reverse process, by the way, is a better explanation of why you can't have too many protons in a nucleus either; protons can decay to neutrons via
$$
p^+ \to n + e^+ + \nu.
$$
It's true that the protons do have an electrostatic repulsion, but what this really does is to raise the proton energy levels relative to the neutron energy levels, meaning that the nucleus will be stable when it has fewer protons than neutrons.