A neutron star forms from the collapsing core of a massive star immediately following the star's exhaustion of it's fusion energy reserves. The outflow of radiation from the stellar core suddenly switches off and the core can no longer support the overlying layers against the inward force of gravity.
The rapidly mounting pressure of the infalling layers squeezes the electrons and protons of the core together to create neutrons and neutrinos. The neutrinos immediately escape into space but the neutrons crowd closer and closer together until they reach the density of an atomic nucleus. The tallest possible mountains on a neutron star can only be about 5mm tall due to their gravity.
At this stage, if the compressed stellar core is less than the Oppenheimer-Volkoff limit of about 3 solar masses, the neutrons are able to resist further collapse. Otherwise, a black hole forms. The star's collapsing middle layers rebound against the newly-formed solid neutron core. This generates a shock wave which heats and blows off the surface layers as a Type II supernova explosion.
Left behind is a rapidly spinning neutron star which has a strong magnetic field with poles that are usually aligned with the pole's of the star's rotation. Two oppositely directed beams of radio waves escape from the poles and sweep around like a lighthouse beam, producing a series of regular radio blips that can be detected from Earth. The result is a pulsar.