There are basically two things to consider:
isospin, originally, when we did not know what neutrons and protons were made up of, this was the only QM characteristic to distuinguish between them. Now we know the structure of nucleons, but isospin remains. Now it is very important to understand that a neutron and a proton can align their isospin, thus (coming a little closer, where the strong force is even stronger) creating a more stable, lower energy QM system. This means, that the nucleus is trying to equalize the number of neutrons and protons. This is the only way to create a lowest energy state, most stable nucleus.
the strong force is very short ranged, wheres the EM force's range is infinite. When you have a big nucleus, consisting of a lot of nucleons, the strong force will not be able to balance the EM repulsion between protons. Now if you have a proton rich nucleus, that is too big, it will not be stable, the nucleus will try to go to a lower energy state, a more stable energy state by converting protons to neutrons, thus, because of isospin, the size of the whole nucleus will decrease too, and the neighboring nucleons will have a stronger (isospin aligned) bond, with lower total energy, a more stable system.
You are asking how the nucleus knows or feels, that it has to go to a lower energy state. In QM, it is all about probabilities. It is a misconception that the proton is stable. It is only stable if it is free. Inside the nucleus, the proton will decay. Neutrons are unstable, so they will decay too.
Now you might be asking about beta decay.
In nuclear physics, beta decay (β-decay) is a type of radioactive decay in which a beta particle (fast energetic electron or positron) is emitted from an atomic nucleus. For example, beta decay of a neutron transforms it into a proton by the emission of an electron accompanied by an antineutrino, or conversely a proton is converted into a neutron by the emission of a positron (positron emission) with a neutrino, thus changing the nuclide type.
You are saying that two electrons will repel, because they are repelled by a mediator. Now this mediator is a virtual photon. It is a mathematical description of how the EM field of the electron interacts with the other electron. In reality, we do not know how they interact. We have experiments, and the mathematical description of virtual photons fits the data.
Now in beta decay, the whole nucleus's instability does not act directly on the neutron or the proton to make it decay. It is the forces:
strong force attracts
EM force repels
Now the isospin matters too. The nucleus as a whole moves toward the lowest energy state possible. That is if the neutrons and protons number is equalized. And if a nucleus is too big, the strong force can't balance the EM repulsion of the protons. So you:
can't go too big, because big nuclei are unstable (strong vs EM force)
can't have too many protons or too many neutrons, they need to be balanced (isospin)
In QM, it is all about probabilities. The protons and neutrons inside the nucleus are unstable themselves, not just the whole nucleus. They will decay. Thus, they move toward a more stable nucleus.
The answer to your question is that the whole nucleus's unstability does not act on the quarks directly. It is the neutrons and protons themselves that are unstable inside the nucleus and will decay.