Both ships found themselves in situations where they couldn't outmaneuver, outrun, or fight off their pursuers, yet they both seemed to fight until they went under, with terrible loss of life.
Wouldn't the British have allowed them to surrender, and possibly save the crew? Why wouldn't that have been a preferable outcome for their commanders?
There was one example of a German capital ship that was scuttled after being placed in an impossible situation. In December 1939, three British cruisers engaged the German large cruiser Graf Spee at the Battle of the River Plate. During the battle, Graf Spee suffered minor but significant damage, with her galley and bakery being destroyed and hull damage that limited her sea-keeping ability. her captain, Hans Langsdorff, sought shelter and repairs in Montevideo, but was only allowed to stay for 72 hours by Uruguayan authorities. Unable to fully make the repairs required, low on ammo and believing that there was a strong British force offshore, Langsdorff chose to scuttle the ship. However, her crew did not surrender to the British, but were instead taken off by the German tanker Tacoma. Langsdorff, ashamed at the loss of his ship and not wanting to face the consequences back in Germany, committed suicide shortly afterwards.
The aftermath of the scuttling of the Graf Spee helps to explain why other German captains chose to fight rather than scuttling, even in helpless situations. Hitler was highly angry that Langsdorff had chosen not to fight. Admiral Raeder, who commanded the German surface fleet, received a tirade to this effect. Raeder was ordered to ensure that this would never happen again. In turn, Raeder commanded that any German warship would fight until either it won or the ship was sunk. This pressure from above helps to explain why captains chose to fight rather than surrender. Scuttling their ships would expose them, and possibly their families, to censure and reprisals. In the run-up to Operation Rheinübung, Bismarck's sortie of May 1941, the overall commander Admiral Lütjens told Admiral Marschall (a previous fleet commander, removed due to failure to follow orders during the Norwegian Campaign) that he had no interest in being the third admiral removed from command for not following orders.
This, and Langsdorff's suicide, link into another reason - personal and national honour and pride. To be put into a position where you could command a capital ship required you to be a long-standing naval officer, and at least somewhat aligned with the goals of the regime. Capital ships, meanwhile, were heavily prestigious symbols of naval power for a regime. To scuttle one without a fight was massively humiliating, a major propaganda victory for your enemy. To be recognised as the person who commanded that was an incredible personal humiliation. It meant turning your back on your whole career, giving up what you had spent living for. This was a very hard choice to make - seen through a lens of tarnished personal honour and professional pride, Langsdorff's suicide makes sense.
Another issue was that these officers had often accepted that they were taking massive risks. In the run-up to Bismarck's sortie, Lütjens conferred with a number of naval officers with whom he was close friends. He told Admiral Voss that "I would like to make my final farewells; I will never come back", and Admiral Patzig that "I realise in this unequal struggle with their navy and ours I shall sooner or later have to lose my life". He also told Patzig that he had sorted out his affairs, and was ready to act in an 'honourable manner'. This fatalism likely affected his willingness to surrender his command; if he had accepted he was going to die, he might well have felt it was better to go down fighting, rather than commit suicide in ingnominy.
A final problem was that sometimes it wasn't clear that a ship was put in an inescapable situation until too late. At North Cape, Scharnhorst was chasing three British cruisers when she was ambushed at close range by the British battleship Duke of York. Turning away from this ambush to escape at high speeds, she was suddenly slowed by a lucky hit from Duke of York. This allowed British destroyers to close in and slow her further through torpedo attacks, in turn letting the British battleship and cruisers close the range to finish her off through shelling and torpedoes. The fast pace and confused nature of this engagement gave the German commander, Erich Bey, relatively little chance to surrender with his ship's crew intact, especially in an Arctic winter night.
Thefourthmaninaboat’s answer has already covered some specific factors at stake for Bismarck and Scharnhorst. I’d like to touch on a more general issue for twentieth-century naval combat: surrendering is hard.
The traditional concepts pertaining to surrendering in naval combat, like the idea that it was acceptably honorable to strike one’s colours when it became apparent that victory was out of reach, developed during the Age of Sail. At this time:
Sinking ships in combat was quite difficult and not very common; men-of-war were stoutly-built, and round shot was good at killing crew through splintering but bad at sinking the ship. Enemies typically weren’t interested in sinking the ship, anyway, as capturing it would earn prize money and a repairable hull to put back into service. If it looked like your ship might eventually be sunk in battle, there was ample time to decide to surrender. It would also be very unlikely for one ‘lucky hit’ to turn the tide of the battle; a ship that was outgunned would be likely to keep taking worse fire and eventually be crippled.
Combat took place at close range. Targets had to be identified visually, guns had to be aimed for direct fire, and metallurgy couldn’t support the chamber pressures required to shoot more than a couple of miles anyway. Most battles that were decisive enough to result in anyone considering surrender would be happening at a distance where it was very easy to see that your opponent wanted to surrender.
By the turn of the twentieth century, both of these no longer apply.
Ships are now armoured, but they’re also now mounting much larger guns, and these guns fire shells that weigh half a ton and are filled with explosives. One good hit from these guns can cripple a warship, or even sink her outright if a magazine is pierced. This means that trying to surrender could be catastrophic if the enemy get a good hit in because you’ve stopped fighting back. It also means that a ship that’s losing still has a chance at evening the odds with a lucky hit on her way down, so it becomes harder to justify surrendering as continuing to fight could always affect the result. Furthermore, ships that are put out of action by explosive shells are going to be so heavily damaged that putting them back into service is a major undertaking, so there’s much less of an incentive to capture ships rather than sinking them.
Naval combat also suddenly shifted to much longer ranges. In the US Civil War, naval gunnery was still at ranges that would have been familiar to Nelson. At Lissa (1866), the first battle between ironclad fleets, the guns were too weak so the fight was still at point-blank range and even involved ramming. But in the Spanish-American war (1898), the US ships were able to destroy Spanish fleets at unheard-of ranges of two to five thousand yards. By the Battle of Tsushima (1905), the Japanese fleet demolished the Russians from six thousand metres, and landed effective shots at twelve thousand metres. At such ranges, it was now very difficult for the losing side to communicate any intention to surrender.
Tsushima was the last fleet action where major warships of the losing side surrendered at sea. They had a lot of difficulty doing that, as the Japanese first misunderstood the signal flags raised by the Russians, then doubted whether the Russian’s white flag of surrender was sincere, and then thought the Russians were still trying to flee because their engines weren’t stopped. Admiral Nebogatov had to stop his ships and raise Japanese flags before his intent to surrender was understood.