There's an important distinction to be made here. The British "Force H" which attacked the French ships at Mers-el-Kébir in "Operation Catapult" did not in fact attack an ally. They attacked a former ally.
After the armistice of Compiègne the French fleet was under the control of the Vichy regime, which was neither an ally of Germany nor an ally of Britain. Marshal Pétains goal was that of a neutral France, which for obvious reasons meant significant concessions towards the German occupants. Now, when Operation Catapult took place (only 11 days after the armistice) things were still very much in motion and nobody knew exactly which role France was to play for the remainder of the war. It's obvious that the Kriegsmarine had it's eyes on the pride of the French navy assembled in Mers-el-Kébir, but at this point there were no precise agreements about what should happen with the ships between Nazis Germany and Vichy France. The armistice calls for the French fleet to "demobilize" and "lay up", crucially with an exeption made for the control of the French colonial empire (Article VIII).
As you can see, this does not specify which ships France would retain control over and while it does say that the rest would be demobilized Churchill was very sceptical. For good reasons. Should the entire French fleet fall into the hands of the Axis suddenly the British fleet would look at a daunting task fighting the combined navies of Germany, Italy and France in what at that time looked as a fight for bare survival. Note that at this point, everyone expected an invasion of Britain, something Germany already prepared for, and the best defense Britain had was their superior navy which could render the Channel into almost insurmountable barrier - something the German Kriegsmarine was very much aware of.
So despite Britain and Vichy France being not at war the British decided to make sure the French can't give up control of their most capable naval units to the axis powers. But at this point, Britain and Vichy France weren't allies either. If they would have been, the French ships would certainly have sailed towards British ports, as the German Kriegsmarine would have been incapable of stopping them.
In essence it was less a "Kill our allies forces before the enemy can get to them" than a "Kill a neutral force before it turns into an enemy" if that makes any sense.
And if we're looking for other examples like that we absolutely do find others. One of which happens only three years later:
After the Allied forces successfully invaded Sicily in Operation Husky Benito Mussolini was overthrown and the new government began negotiations for a armistice, which would be made official 8th of September 1943. This armistice included a the surrender of the Italian navy to the Allies at Malta.
When the Germans found out about this they immediately prepared an airstrike against the most modern Italian units, the battleships Littorio/Italia and Roma, utilizing the revolutionary Fritz X guided bombs to severely damage the former and sink the latter.
Now there are some significant differences between those two actions. The British gave the French force an ultimatum, whereas the Germans attacked without warning - considering the fact that the exact fate of the French force was unclear, while the Italian force was certainly going to be used agains the Germans, makes a lot of sense. Also one could go into the nitty gritty details of how exactly the diplomatic relations between Britain and France on the one hand and Germany and Italy on the other were different, both before the respective armistice and after. But since those are somewhat similar operations in relatively short succession I though it would fit your question.