Probably based on the story of the massacre of the Cathars in southern France in the Albegnesian crusade.
The Abbot of Citeaux, Arnaud Amalric, leader of the pope’s forces, was asked how they would know who were the heretics during the sack of Béziers in 1209. Allegedly he said “Caedite eos. Novit enim Dominus qui sunt eius - Kill them all for the Lord knoweth them that are His”
(Also paraphrased as “Kill them all, God will know His own”, “Kill them all, God will sort his own”, or “Kill them all,/and let God sort them out” )
No doubt other soldiers have been rephrasing it to be clever since that time.