What happens to Protons and Electrons when a Neutron star forms?

It is the Pauli Exclusion Principle that actually allows the formation of a "neutron" star.

In an "ordinary" gas of protons and electrons, nothing would happen - we call that ionized hydrogen! However, when you squeeze, lots of interesting things happen. The first is that the electrons become "degenerate". The Pauli exclusion principle forbids more than two electrons (one spin up the other spin down) from occupying the same momentum eigenstate (particles in a box occupy quantised momentum states).

In that case what happens is that the electrons "fill up" the low momentum/low energy states and are then forced to fill increasingly higher momentum/energy states. The electrons with large momentum consequently exert a degeneracy pressure, and it is this pressure that supports white dwarf stars.

If the density is increased even further - the energies of degenerate electrons at the top of the momentum/energy distribution get so large that they are capable of interacting with protons (via the weak nuclear force) in a process called inverse beta decay (sometimes referred to as electron capture when the proton is part of a nucleus) to produce a neutron and a neutrino. $$p + e \rightarrow n + \nu_e$$ Ordinarily, this endothermic process does not occur, or if it does, the free neutron decays back into a proton and electron. However at the densities in a neutron star, not only can the degenerate electrons have sufficient energy to instigate this reaction, their degeneracy also blocks neutrons from decaying back into electrons and protons. The same is also true of the protons (also fermions), which are also degenerate at neutron star densities.

The net result is an equilibrium between inverse beta decay and beta decay. If too many neutrons are produced, the drop in electron/proton densities leaves holes at the top of their respective energy distributions that can be filled by decaying neutrons. However if too many neutrons decay, the electrons and protons at the tops of their respective energy distributions have sufficient energies to create new neutrons.

Mathematically, this equilibrium is expressed as $$E_{F,p} + E_{F,e} = E_{F,n},$$ where these are the "Fermi energies" of the degenerate protons, electrons and neutrons respectively, and we have the additional constraint that the Fermi momenta of the electrons and protons are identical (since their number densities would be the same).

At neutron star densities (a few $\times 10^{17}$ kg/m$^{3}$) the ratio of neutrons to protons is of order 100. (The number of protons equals the number of electrons).

This calculation assumes ideal (non-interacting) fermion gases. At even higher densities (cores of neutron stars) the strong interaction between nucleons in the asymmetric nuclear matter alters the equilibrium above and causes the n/p ratio to decrease to closer to 10.