The Lajnah (Permanent Committee For Scholarly Research And Ifta’) said, after they studied the issue:

“Based on what was reported in the question regarding the method of extracting this dye [color] from these insects after melting them, grinding them, straining them, and extracting the solid parts and based on the fact that the color is a trace and not the insect itself which is repugnant to eat, it is allowed to benefit from this color in foods or drinks as long as it is not harmful. What proves that the trace of something repugnant is not that repugnant thing itself and that the trace is permissible even if the source is impermissible itself is the statement of the Prophet (ﷺ):

إذا وقع الذباب في إناء أحدكم فليغمسه كله، ثم ليطرحه فإن في أحد جناحيه داء وفي الآخر شفاء

If a fly falls in the vessel of any of you, let him dip all of it (into the vessel) and then throw it away, for in one of its wings there is a disease and in the other there is healing [antidote for it, meaning the treatment for that disease)

[Reported by Bukhari]

He (ﷺ) did not command to pour out the milk although a fly felt into it and a person dipped the fly in it completely. Rather he (ﷺ) ordered for the insect to remain [before removing it] and to benefit from what it fell into [i.e. the drink] which proves the purity of insects. The trace does not effect the sanctity of what it fell into if the harm is removed. So all that proves that benefiting from the color/dye of the insects mentioned in the question in foods and drinks is permissible”

[Reference]

Translated by

Faisal Ibn Abdul Qaadir Ibn Hassan
Abu Sulaymaan