In the Robert E. Howard poem "The Gold and the Grey," the Cimbri women kill themselves with daggers in order to avoid being enslaved by the Romans ("The Cimbri yield no virgin-slaves to glut the lords of Rome!"). One of them kills her rapist and then kills herself.
Subverted in the Evelyn Waugh novel Decline and Fall where one character, Grimes, who is an example of The Barnum tells of "landing in the soup" (an Unusual Euphemism for being caught engaged in homosexual conduct) during World War I and being placed in a room and given a loaded revolver and some whiskey to settle his nerves, so that a court martial could be avoided and the official story would be that he died in combat. After debating this course of action, he decides he would rather live and is found roaring drunk when his fellow soldiers re-enter the room.
Generally averted with Space Marine Battles, as Space Marines believe that going down fighting is the only fate worthy a Space Marine. However, one example plays it straight, as one character realizes that Fate Worse Than Death awaits him and commits suicide by taking rebreather off in the middle of poisonous fog.
In the Book of Judges: "King" Abimalech, after having a millstone dropped on his skull by a woman, manages to survive long enough to ask an attendant to finish him off, to avoid the humiliation of having been killed by a woman. So, Older Than Feudalism.
In the Books of Samuel: In 1 Samuel 31, a wounded King Saul tried to get his armorbearer to kill him so he wouldn't fall into the hands of the Philistines, who he feared would "thrust me through, and abuse me." When the armorbearer refused, Saul killed himself.
Later, in 2 Samuel, a man claimed to have killed Saul on his request, though this was a ploy to ingratiate himself to David. In fact Saul's armorbearer had committed suicide along with his king. The attempt to gain bonus points backfired.
The Eye of the World, Perrin, Egwene, and Elyas are being pursued by an immense flock of demonically-possessed ravens, and suspect they can't reach safety in time. When they do escape, Elyas finds Perrin about to throw his axe into a pond, as he was considering killing himself and Egwene with it rather than allow them to be eaten alive. He asks Perrin which death he really thinks she'd have preferred, and Perrin decides to keep the axe.
Also, in The Gathering Storm some inhabitants of Hinderstap town try to commit a suicide in order not to become mindless monsters set to kill each other at every sunset. This doesn't work, anyway.
In World War Z, there are many of these stories because the book takes place during a Zombie Apocalypse. Most notably, a Russian chaplain decides that he and the other religious figures should be the ones "sending them to God" and the resultant religious fervor turns the postwar Russia into a theocracy.
In Dan Abnett's Gaunt's Ghosts novel The Guns of Tanith, cornered in the control room with no way to work it, Jagdea takes out poison pills to avoid capture. Bonin doesn't let her, and someone who does know how to work arrives in time.
In Animorphs, an unnamed controller scientist decided that he would rather die of Kandrona Starvation (a horrifically painful death) than be killed by Visser Three.
Happens in Romance of the Three Kingdoms. When Guan Yu is captured and executed, his two surviving subordinates, Zhou Cang and Wang Fu, both commit suicide before Maicheng finally falls.
In the Westmark trilogy, Zara combines this with Suicide by Cop. Injured and helpless, facing arrest and interrogation, she deliberately taunts the soldiers arresting her and Theo until one of them kills her.
In Arthur C. Clarke's short story "The Transit of Earth", after his mission is completed the main character faces a slow death marooned on Mars, but ultimately elects to travel to a part of the planet where life has been detected, and allow himself to be consumed by those organisms so his body will remain part of a natural ecosystem.
In The Lord of the Rings, Denethor, insane and sure of defeat in the long run, burns himself to death (and tried to take his son with him) rather than let himself be killed or his corpse fall into the hands of Sauron's forces.
Father Callahan from The Dark Tower. Justified in that he was fighting vampires that would turn him if they got to kill him.
Street Magic has the villain poison herself in her room rather than be arrested and humiliated for killing the local police's undercover agents, as well as countless commoners, since there's no chance in hell that her aristocratic family is going to protect her.
Dayna Jurgens in The Stand. It comes close for her: she attempted to jump through some glass, but Flagg caught her before she could fall to her death. Thinking quickly, she whipped her head around and sliced her throat on some of the broken glass before he could pull her all the way back in. That he could not foresee or prevent this really rattles him.
At the beginning of Moongather, Serroi panics and bolts, leaving a severely injured Tayyan behind. It's later revealed that Tayyan cut her own throat rather than be captured.
In the fourth Safehold book, A Mighty Fortress, Hauwerd Wylsynn decides it's better to be killed than horribly tortured to death by the Inquisition. When the Inquisition finally makes its move, Wylsynn murders his brother (who was going to face his punishment honorably) and then takes on the Church Guardsmen sent to arrest him. He takes down four armed and armored men before finally being cut down.
In Gust Front, Tommy Sunday, Jr, and his future girlfriend make a promise that if one is unable to kill themself, the other will do it for them, instead of leaving them alive for the Posleen to find and invite for dinner.
In Assassin's Creed: Renaissance, Archbishop Salviati chooses suicide to letting Ezio get information on the other conspirators from him.
The Christopher Pike novel Chain Letter 2 has an unusual twist on this. Alison decides to shoot herself when she realizes that her boyfriend Tony was going to kill her under the influence of the Caretaker demon. The twist is that Alison's actions were meant to protect Tony: if Tony obeyed the Caretaker and killed her, the Caretaker would be able to take his soul. If Alison was the one who pulled the trigger, however, the Caretaker would be unable to drag Tony off to Hell. Alison's actions triggered a My God, What Have I Done? moment for Tony. And Alison got better.
Jendara's Suicide by Cop at the end of Green Rider. Justifiably: Her way, she gets run through, and dies quickly and relatively painlessly. If she'd been taken alive, her death would have been hideously painful and drawn out over the course of a month.
In Esther Hautzig's The Endless Steppe: A Girl in Exile, Esther's 85-year-old grandmother Reisa hears that the Nazis are coming to take her to a concentration camp and decides that if it's time for her to die, she wants to die in her own home. Esther says, "It was not suicide; by a supreme act of will, this old woman cheated the Nazis of her death."
In a Star Trek Expanded Universe novel, Praetor Tal'aura (the senator from Star Trek: Nemesis) finds out that a member of an important Romulan family has been plotting behind her back. When captured, he requests to take poison in lieu of a public execution, knowing that the latter will bring great shame to his family. She denies the coward. Later on, she allows a political rival, who was attempting to incite a revolt against her, to drink poison, having respect for the man. Given that Romulans are, essentially, The Roman Empire Recycled In SPACE, this makes sense.
In Krabat, Merten tries to kill himself, after his cousin Michal dies. (It doesn't work.)
At the end of the book of Double Indemnity (not the movie), Walter and Phyllis are spotted on board the ship, and rather than face arrest and execution, they commit mutual suicide by jumping overboard.
At the end of the Dale Brown novel Sky Masters, the Big Bad Admiral Yin, seeing that his plan is foiled, chooses to blow his brains out rather than return to China in defeat, where he will be humiliated and dishonourably executed.
One group of human survivors in The Killing Star who are being actively chased by the alien invaders ultimately choose to destroy themselves along with a fair portion of the Sun rather than risk what might happen to them when they're captured.
In the Queen's Thief series, Eugenides is unable to kill himself, but he asks his father to strangle him rather than survive in the Queen of Attolia's prison; Justified, as she cut off his hand the last time he was prisoner there. The attempt is prevented. On another occasion, he refuses to jump off a cliff because he's chained to two innocent men, both of whom are willing to die with him, who will be able to survive and see their families again.
Invoked in The Belgariad when Silk is captured by Taur Urgas, facing torture and execution come sunrise. Yarblek mentions having attempted to get close enough to slip him a dagger so he can open a vein.
The Hunger Games: during Mockingjay all characters in the rebel army are fitted with a "Nightlock" capsule and expected to kill themselves before they are captured and taken in for torture/questioning.
In Enchantress from the Stars Elana, a 14 years old girl from The Federation, is captured by colonists from The Empire. The colonists intend to bring her to their home planet, where she will be dissected and interrogated (and thanks to their tech, The Empire can extract any information they want). Not wanting to end like this, Elana runs towards the imperial rock-chever, intent on being crushed by falling debris. She is rescued Just in Time, and the imperials are so ... amazed by the way she is rescued that they withdraw and leave her behind.
In Harry Potter, Albus Dumbledore has Severus Snape kill him to prevent Draco Malfoy from doing so and to ingratiate himself (Snape) with Voldemort. When Snape protests to this plan, Dumbledore points out that he would rather die quickly and painlessly than to fall into the hands of Fenrir Greyback or Bellatrix Lestrange, who like to play with their food.
The Saga of the Jomsvikings: When the Jomsviking captain Bui is wounded beyond recovery in the naval Battle of Hjorunga Bay, he jumps overboard to his death.
One terrorist kills himself in the Paladin of Shadows book A Deeper Blue than be taken alive.
In the Dirk Pitt Adventures book Sahara, when it looks like the Malians are about to overrun Fort Foreau, Dirk prepares to kill Eva and the rescued women so the enemy doesn't get to rape them. Fortunately, The Cavalry arrives just in time.
In The Host Melanie and a few other people attempt suicide to prevent being captured and taken over.
Xanatos does this in the eighth Jedi Apprentice book when his crimes are exposed and he's cornered by Qui-Gon and Obi-Wan. He jumps into one of the acid pools his company created on Telos.
In The Lost Fleet: Beyond the Frontier follow-up trilogy, the bear-cows are Absolute Xenophobes who view any predator as a natural threat that must be eliminated at all costs and any other fellow herbivore as competition for the same resources who must also be eliminated. Protecting the herd is more important to them than any individual life. During the attempt by The AllianceSpace Marines to take the crippled bear-cow superbattleship, thousands of bear-cow crewmembers hurl themselves at the marines without regard. Any of them who are wounded are finished off by their own comrades in order to spare them from being eaten alive by the predators (they assume any predator, including humans, wants to eat them). For the same reason, any bear-cow taken alive will kill itself through a naturally-developed method of stopping higher brain functions rather than be eaten alive. They don't bother talking to anyone to find out if they will be actually eaten.
Invoked multiple times in Frostflower and Thorn. The death penalty in this world tends to be very harsh, involving basically being slowly tortured to death, so the main characters are almost as preoccupied with not being captured alive in case of failure as with achieving their goals.
Appears on a massive scale in Richard Matheson's short story "The Creeping Terror." The city of Los Angeles is revealed to be sentient, and, as the title implies, slowly grows to take over the entire United States. As it does, it brainwashes everyone it comes into contact with, making them lose their past identities and become shallow, Hollywood-obsessed bimbos. When Los Angeles reaches Boston, the entire population of the city decides to commit mass suicide rather than surrender their free will.
In the Newsflesh world, most whose job involves facing zombies make it a rule to save a bullet for themselves, rather than be killed or converted by a zombie mob.
In the Paradox Trilogy, when Devi is besieged by xith'cal aboard one of their tribe ships, she counts her ammunition so that she can save her last bullet for herself, as the xith'cal are known practitioners of To Serve Man and shooting herself would be preferable to being eaten. Fortunately, a rescuer arrives to help just as she presses her gun to her head.
In Awake in the Night Land, people who adventure to the titular Night Land have a Cyanide Pill in their arms so they can bite it in a hopeless situation, which is to prevent the lovecraftian monsters of the setting from Destroying their souls.
Ciaphas Cain: The Greater Good sees Tau Water Caste and Imperial Navy vessels self-destructing rather than have the biomass of their crews consumed by a tyranid hive fleet. In the latter case it's mentioned there's a recording of a Navy ship's chief engineer triggering the reactor overload sequence moments before being torn apart by tyranid boarders.
In Firefight Megan shoots herself in the head with a remote trigger mechanism rather than be burned alive. In addition to being over a lot faster, fire is her weakness; burning would negate her Resurrective Immortality and actually kill her.
In Horus Heresy: The Flight of the Eisenstein When Horus bombs Istvaan III with the life eater virus, both the dreadnought Huron-Fal and Ullis Temeter, one of the captains of the Death Guard gets infected by the virus. While they both agonize due to the extremely painful effects of the virus, Huron-Fal detonates the core of the giant dreadnought armor, causing an explosion that kills them both.
"This death... This death is ours. We choose it. We deny you your victory."
The Histories of Herodotus: After avenging her brother by killing a "a vast number of Egyptians", Queen Nitocris of Egypt suffocates herself in a room full of hot ashes to escape being killed at the hands of her people.
In the first Wings of Fire book, Peril is pitted in a life-or-death battle against a dragon named Horizon. Peril always wins her battles because her scales burn to the touch. Realizing that he can't win and that his death will be slow and painful, Horizon decides to grab hold of Peril and burn himself to death quickly.
The Warrior Cats book Thunder and Shadow features a bonus scene in the Barnes and Noble edition, in which Needlepaw (prior to us meeting her in the series) is picked up and carried off by an owl. She decides she'd rather die by falling (by her own choice) than let it kill and eat her, so she fights until it lets go (and survives the fall).
In The Stormlight Archive, when the Soulcasting savant Kaza realizes that she's been fatally poisoned, she uses the last of her power to transmute her body into smoke. Having spent her entire life in a Gilded Cage, she hugely values her freedom, even if only in choosing the manner of her death — and in denying her killer the priceless artifact she's holding.