Edit: Wikipedia isn't very helpful, I may just be too dumb to understand this paragraph:
"When bound inside of a nucleus, the instability of a single neutron to beta decay is balanced against the instability that would be acquired by the nucleus as a whole if an additional proton were to participate in repulsive interactions with the other protons that are already present in the nucleus. As such, although free neutrons are unstable, bound neutrons are not necessarily so. The same reasoning explains why protons, which are stable in empty space, may transform into neutrons when bound inside of a nucleus."