Classically speaking it's easy to think of it in the following way:
Even if you have a repeling force (electromagntic), you still have an attractive one (nuclear force). So at the end as long as those two cancel each other out, protons can stay together. For larger nuclei with many protons, there needs to be enough neutrons too in order for the nuclei to be stable (as a general rule)...
Quantum mechanically you have a very complex dynamical system that exists in a bound state.