In July 1940 the French fleet in Algeria was destroyed by the Royal Navy to prevent it falling into the hands of the Germans. Before the destruction, the French navy had been given an ultimatum with four options:
"(a) Sail with us and continue the fight until victory against the Germans.
(b) Sail with reduced crews under our control to a British port. The reduced crews would be repatriated at the earliest moment.
If either of these courses is adopted by you we will restore your ships to France at the conclusion of the war or pay full compensation if they are damaged meanwhile.
(c) Alternatively if you feel bound to stipulate that your ships should not be used against the Germans lest they break the Armistice, then sail them with us with reduced crews to some French port in the West Indies — Martinique for instance – where they can be demilitarised to our satisfaction, or perhaps be entrusted to the United States and remain safe until the end of the war, the crews being repatriated.
If you refuse these fair offers, I must with profound regret, require you to sink your ships within 6 hours."
(from Wikipedia)
The French navy refused any of the options of the ultimatum and thus the Royal Navy fired upon the fleet to destroy it (killing 1,297 French servicemen).
Why didn't the French hand over the ships, or sail them to the French colonies in the West Indies, or give them to the US for safekeeping? It seems to me like they must have either let their own pride get in the way of a logical decision or they genuinely thought they could continue the war with Germany on their own (despite the armistice they had just signed).
Not unreasonably, the French felt that having signed an armistice with the Germans which kept the ships under French control was good enough. That there was no need to take additional steps to keep them out of German hands. As you'll note from the wiki article Admiral Darlan had personally assured Churchill that the fleet would not be surrendered.
There's also something of a policy angle to keeping the ships under French control. The fleet was pretty much the only leverage the French had. In large part the Germans had agreed to the peace in order to keep the fleet out of British hands. If the French gave up control in any way the the Germans would likely simply occupy the portion of France they didn't already control.
The British were mostly concerned that the Germans would seize the ships by surprise at some point. In truth, since they were in North Africa, the ships that the Royal Navy sank were actually those furthest from German control and least likely to be captured. The bulk of the French fleet was in Toulon in Southern France.
This was addressed in this thread and also in a reddit TIL.
The French fleet answered to France and not to Britain. As such their objective would have been to do the best thing for France and not for Britain, including retaining a modicum of independence. Surrendering the fleet or having it interned by a neutral power wouldn't appear to be the best course in this regard
France (vichy france) had just signed an armistice with Germany that explicitly addressed the French navy; it would have been seen as a rather massive violation, and opened the door to reprisals against France.
Article 8 of the Armistice agreement:
"The French war fleet is to collect in ports to be designated more particularly, and under German and/or Italian control to demobilize and lay up—with the exception of those units released to the French Government for protection of French interests in its colonial empire.
The peacetime stations of ships should control the designation of ports.
The German Government solemnly declares to the French Government that it does not intend to use the French War Fleet which is in harbors under German control for its purposes in war, with the exception of units necessary for the purposes of guarding the coast and sweeping mines.
It further solemnly and expressly declares that it does not intend to bring up any demands respecting the French War Fleet at the conclusion of a peace.
All warships outside France are to be recalled to France with the exception of that portion of the French War Fleet which shall be designated to represent French interests in the colonial empire."
Admiral Darlan never received the full text of the ultimatum, most significantly the part about removing the fleet to American waters.
Darlan had personally promised Churchill that "no French ship will ever come into the hands of the Germans."
At that point in time, it might have been felt probable that the Germans win the war and the British sue for peace (in fact Mers al kebir would turn out to be a bold declaration from Britain to stand)
In the final talks, Gensoul had shown Holland a copy of his orders from Admiral Darlan that " if any foreign power were to try to seize control of the French fleet they were to immediately set sail either for the United States or be scuttled". However, the ultimatum and events had progressed too far, the british felt he was stalling for time and were afraid based upon an intercepted response to an earlier communique from him that he would be reinforced.
By some accounts, Admiral Gensoul was doing a certain degree of bluffing in that he didn't really think the British would open fire.
By most accounts Gensoul had his pride and it rankled to be asked to submit/negotiate at gunpoint; however it is clear that the ultimatum had boxed both sides in.
They probably didn't think the British would sink ships and kill men that saved British lives when they fled Dunkirk.
The order was given by Darlan to sabotage the ships rather than let them fall into German hands, so there was no real threat to Britain's security either. No real justification to fire on allies. The French sailors kept their words two years later in Toulon when they destroyed the remaining part of our fleet rather than give it up to the Germans who were advancing on the port with tanks.