Isotopes form in the sun and other stars. Stars are composed of the simplest elements, hydrogen. Under high temperature and pressure (due to the sun's gravity) two hydrogen atoms are squeezed together which forms slightly larger elements such as helium. Two helium atoms can fuse together to create beryllium. In this manner the smaller elements are fused. These reactions are called fusion reactions and release energy.
The larger isotopes are formed later in the star's life cycle, when most of the fusible material has been consumed. Some very massive stars will undergo a supernova explosion during which the elements and remaining material are forced out, away from the center of the star. Atoms will attract other atoms or other material. A wide variety of isotopes can form during a supernova. Many of the isotopes formed during this process are unstable and will spontaneously change in order to become more stable.
The ChemMatters article referenced explains the process thoroughly. I highly recommend the read. Hope this helps!