Idhā mā l-māʾu khālaṭahā and idhā mā dhāqahā use idhā to indicate when or under what condition an event happens. The accompanying mā may be treated as emphatic or additional, not necessarily as a relative pronoun.
In contrast, wa-mā sharru l-thalāthati biṣāḥibiki uses mā for negation. Syntax, not the isolated spelling, determines the function of the particle.