Neutrons can “remain” indefinitely stable in the nuclei belonging to certain isotopes, most probably in those of atomic number lower than that of iron (Z=26), although they can also remain stable in heavier nuclei.
However, when neutrons are released as a result of either a fusion reaction (such as those occurring in the sun, for example H + H à He + n) or a fission reaction on Earth, or their separation from a nucleus induced by a muon (originating in a cosmic ray hitting the atmosphere), several situations can happen with it: (i) one is that it is captured by the nucleus of an isotope and becomes part of the nucleus of another stable isotope of the same element or chemical compound (light water to heavy water, H20 to D20). ii) Another is that fission releases neutrons, in which case any of the reactions i), ii) can be repeated. And the last iv) is that at least one neutron released is not “captured” in any of the processes described so that it becomes a “free neutron”.
A neutron consists of one “up” quark and two “down” quarks. Mediated by the weak interaction of matter, after some time the free neutron will undergo beta decay, that is, the weak interaction (acting through a W_ gauge boson) transforms one of the down quarks into an up quark, giving rise to a proton, also emitting an electron and an anti-neutrino of the electron type.
The half-life of a free neutron before undergoing beta decay is just under 15 minutes, although there are discrepancies about the exact value due to differences between different measurement methods (one is to capture neutrons in a container and count how many are left after a fixed time; another is to measure how many neutrons in a beam are transformed into protons in a given space).
The reason why a neutron decays after a few minutes in the free state is that while it is part of a nucleus, the strong interaction prevails, which prevents the quarks from mutating “flavor”. On the contrary, when the neutron is released from the nucleus, it is the weak interaction that predominates and does not prevent the quarks from mutating, and the particle (neutron) will look for a state of lower energy, in this case, the proton, since we know that it has a mass of 938.27 MeV against 939.56 MeV of the neutron. That is why free neutrons cannot remain ad infinitum like this.
However, there is a theoretical exception: when a star consumes all its fuel, sometimes (stars between 4 and 8 times the mass of the Sun) the gravitational forces cause protons and electrons in its core to contract and form neutrons (and emit neutrinos), becoming a “neutron star”, with a radius of no more than 10 km but very dense. The properties of neutrons (Fermi's law) prevent a major collapse so that due to high pressures and temperatures, they could reach states other than those well understood so far, for example, “cubic neutrons” that would allow them to stay together without decaying any longer in a “neutron soup”, in a super-fluid state that would prevent them from decaying in the way described above. Neutron stars emit high-energy neutrinos, which gradually cool them down.