This happens only for one type of nucleus. This process is known as Electron Capture. You can find the details by searching this term.
An electron capture converts a proton to a neutron, and releases a neutrino.
This is when the nucleus has a high number of protons. There are fewer neutrons in the nucleus than other stable isotopes. Capturing an electron makes the nucleus more stable and lowers its energy.
The electron is emitted from the lower electron shells. It is then quickly replaced by an electron “falling” in from an outer shell.
There is a lot of interesting stuff happening – thank you for asking.