I’m just wondering if any astronauts have gotten cold feet last minute and have refused to go into space.
Some Shuttle/ISS examples of crewmembers who completed training, were assigned to a flight, but declined/left/had issues/got reassigned:
- Joan Higginbotham. Left NASA after being assigned to her 2nd flight, STS-126.
- Jeff Ashby. Was assigned to his first flight as pilot of STS-87 but stepped down due to family issues. Went on to fly two flights as pilot and command a third.
- Gus Loria. Assigned as pilot on STS-113 but stepped down due to medical issues. Subsequently left NASA.
- Mark Lee. Assigned as MS on STS-98 (would have been his fifth mission), but was removed. Subsequently left NASA.
- Jeanette Epps. Assigned to ISS Expedition 58/59 but was removed.
Not really a "bail-out", but still a late change, was swapping the crews from Apollo 13 and Apollo 14. The original crew for Apollo 13 was to be commanded by Alan Shepard, but he had recently received surgery for an inner ear infection and NASA deemed he needed more time to recover for certain. So a crew led by Jim Lovell, slated for Apollo 14, was swapped in. (In response to a comment, note that none of the astronauts swapped into Apollo 14 got cold feet, rather the NASA brass did so over Shepard's inner ear infection/surgery.)
Lovell was thereby doomed to miss landing on the Moon but destined to become a national hero.
It would appear the answer is no (to the absolute best of my googling ability).
Only three astronauts have quit during training: Brian O'Leary in April 1968, John Llewellyn in September 1968, and Robb Kulin in August of 2018. O'Leary thought he would probably never fly, and Llewellyn had some issues with the required (at the time) jet aircraft training, whereas Kulin's reason for quitting was only listed as "personal." In fact, NASA refused to disclose any reason due to privacy laws. Barring an alternate explanation it seems he really just decided not to follow through with becoming an astronaut.
EDIT: I don't know why I didn't also focus on astronauts who never flew, but of course this SE always delivers. It seems that all of these astronauts just got unlucky mission selection (or lack thereof), or died before getting their ride to space. As far as I can tell, none got assigned a mission and backed out of their own accord.
EDIT 2: There are numerous cases of astronauts being replaced before launch (almost always for medical reasons or major medical issues in the family). This article does a good job summarizing those, and notes that Timothy Kopra is the replacement closest to launch - at only six weeks.
If an astronaut backed out just before a mission (i.e. after standard and mission-specific training had taken place), it doesn't seem to be disclosed by NASA. Sorry that this answer is essentially "well not that I can tell."
Alexey Leonov's crew was primary for doomed Soyuz-11.
Two days before launch the crewman Valeri Kubasov had a heath issue, so the reserve crew was assigned. All three crewmembers died because of depressurisation just before atmospheric reentry.