So some of the mass is converted into energy when neutrons and protons combine to form nucleus. Why? And how? And then why do we need to supply the same amount of energy to separate them?
In classical mechanics, it is easy to understand that a ball lying on the floor is bound to the earth, and can only be freed by giving it kinetic energy.
Neutrons and protons and nuclear physics are in the regime of quantum mechanics, and cannot be described with classical mechanics, and also in the regime of special relativity. It is not easy to understand the concepts without using the mathematical theoretical models.
In particular the concept of mass and the concept of energy has been extended in order to fit the regime of particle physics. One has in defining a particle, instead of kinetic energy described by $1/2mv^2$, $v$ the velocity vector, a four vector of total energy E and the momentum vector, $(E, p_x,p_y,p_z)$ such that the length of this four vector is the invariant mass of the particle, This means that in any transformations the mass of the electron is invariant, the mass of the muon is invariant, etc. for elementary particles.
Neutrons and protons combine to form nuclei, but neutrons and protons themselves are composite of quarks in a complicated manner. Still the four vector algebra ensures that their mass, the four-vector sum of all the masses, is invariant.
In a similar way that the ball bound to the earth needs energy to be free,the bound states of protons and neutrons forming a nucleus, will need energy in order to be free, and give up energy when being bound. Because of the four vector definition of energy and mass and the algebra involved, the sum of the free invariant masses is larger than the mass of the bound system.
A nucleus is a complicated object, so let's start with the simplest possible bound system of a positronium atom i.e. a bound state of an electron and a positron. This shows the same phenomenon as the nuclei because the mass of the positronium atom is less than the sum of the electron and positron mass (by $6.8$ eV)¹. So just like the nucleus some of the mass disappeared when the two particles formed the bound state. How can this happen? How can mass just disappear?
A quick disclaimer: I'm going to dangerously oversimplify and I can already hear experienced physicists fainting with horror. Don't take what follows too literally. My aim is to give a feel for why mass can vary in a popular science rather than a rigorous way.
To answer this we need to understand how particles are described in quantum field theory. We assume there is a quantum field that fills all of spacetime, then the things we call particles are actually excited states of this field. That is, we can start with the field in its ground state, add 511 keV to it and this excites the field to form an electron. Alternatively if the field is in an excited state we can remove 511 keV from it and this destroys an electron. Likewise there are also states of this field that correspond to positrons, so we can also add and remove energy to create and annihilate positrons.
This probably seems an odd way of describing particles, but it makes many things easier to understand. For example it neatly explains how particles are created in colliders - the kinetic energy of the colliding particles is transferred into quantum fields where it creates new particles.
Anyhow, back to our mass deficit. I've said electrons are excited states of a quantum field, but there is more to it than that. The things that we call electrons are strictly speaking a special sort of excited state called a Fock state. You may have solved the Schrodinger equation for a free particle and learned the answer was an infinite plane wave, and this infinite plane wave roughly corresponds to a Fock state of the field. This Fock state has a rest mass (due to an interaction with the Higgs field) of $m_e$ for the electron and positron, so if we start with a free electron and positron the total mass is $2m_e$.
But, and this is where we finally get around to answering your question, a quantum field can have excited states that are not Fock states and therefore do not describe free particles. Specifically, in a positronium atom the electron and positron are bound together instead of being free particles, and this new state of the field is not just some combination of the two Fock states for each particle. Since it is not just a combination of the two Fock states there is no reason why it must have the same mass as the two particles that formed it, and indeed it doesn't. This is the reason why the mass of the bound state can be different.
I hope I've convinced you that it seems plausible that the mass of a bound state can be different from the total mass particles that combined to form it, but I haven't said how the mass of the bound state differs. That comes from energy conservation. If we start with our electron and positron and combine them into a positronium atom this lowers the energy by $6.8 eV$ so we have to take $6.8$ eV out of the system e.g. by emitting a photon. Then Einstein's famous equation $E = mc^2$ tells us that this decreases the mass by $6.8$ eV/c².
¹ actually I don't think the mass of a positronium atom can be measured to an accuracy of less than $6.8$ eV/c² so this isn't confirmed experimentally. However it has been confirmed for a hydrogen atom where the mass really is $13.6$ eV/c² less than the combined mass of an electron and proton. I didn't use a hydrogen atom in my answer because the proton is not a fundamental particle.
The easy way to look at this is as follows:
There is a powerful force which makes protons attract neutrons and once they touch, it holds them together really, really hard.
So if we were to place a proton and a neutron next to each other, they will experience that force, and as they move toward each other in response, the force on each moves through a distance. (Force) * (distance) = work, which represents spent energy.
That energy had to come from somewhere. Now since mass and energy can be converted back and forth from one form to the other, the energy used up to pull the particles together gets subtracted from their mass- so that the bound state of one proton plus one neutron weighs a little bit less than the sum of their two masses when they are apart.
That mass difference then shows up as electromagnetic and kinetic energy which the bound pair then get rid of- and which is where the gigantic energy release in a hydrogen bomb comes from.
And this means that to yank those two bound particles apart again, you have to do work on them, which stores energy in them, which increases their mass by just a little bit.
I answer the question in the context that a nucleus of neutrons and protons does not exist without the existence of a similar number of protons to electrons.
If one accepts that an atom is therefore largely electrically neutral because the electric fields of the protons and electrons not only compensate each other, but these two interacting subatomic particles partially strip off their fields in the form of photons, then it becomes clear that a loss of mass-energy can be observed.
Our reflections on this process are based on the assumption that not only does a free electric particle have a constant electric charge (experiments by Robert Andrews Millikan 1910), but this also applies to particles in the bound state in the atom. The assumption that the neutrality of the atom and the emission/absorption of photons during the approach/removal of electrons to/from the nucleus could be due to a reduction in the electric fields of the proton and electron does not appear in any theory to my knowledge, but would be worth considering.
I find the question of the loss of mass of the proton/neutron interaction secondary, as it is primarily about the proton/electron interaction.