Firstly you have to get a rough idea of four fundamental forces of nature.
There are four fundamental forces in nature.
2.The weak nuclear force.
4.The strong nuclear force.
The list is in ascending order in terms of strength.
Proton repelling each other is due electro magnetic force but protons and neutrons sticking to each other is due to strong nuclear force. As strong nuclear force is greater than electro magnetic force, the nucleus has protons and neutrons sticking to each other.
If there exists strong nuclear force, the proton should not repel in the 1st case? How is this possible?
Ans: We know that the electromagnetic force is inversely proportional to r2 but the strong nuclear force decreases exponentially. As a result, strong nuclear force has a small coverage as compared to electromagnetic force and at a larger (as compared to distance between protons and neutrons) distance electromagnetic force tends to have higher magnitude which suppresses the strong nuclear force resulting in repulsion.
Hope it helps you. Comment if you are not satisfied with anything.