The Germans often violated their own racial purity laws because simply put they needed as much help as they could get. It was a case of sticking to your "principles" and losing or temporarily compromising them and having a shot at winning. The Germans found plenty of nationalities willing to fight with them against common enemies. There were plenty of people who hated the Soviet Union and the British Empire and thus found natural allies in the Germans.
In the case of the Indian Legion. That was due in large part to the work of Subhas Chandra Bose, who was a driving factor in the creation of the India legion out of POWs that the Germans got in North Africa. The Germans and Adolf Hitler had long identified that India was a crucial part of the British Empire. In WW1 they had tried to incite a revolt in the area, and in WW2 they hoped that the creation of an India legion would help weaken Britain's hold over its Indian Empire. It also gave the Germans an extra source of manpower.
Now in the case of the Handschar unit. The Germans and Muslims held a common enemy, the Jews. The Germans found an ally in Haj Amin al-Husseini, the Grand Mufti of Jerusalem. Hitler promised that he would kick the Jews out of Palestine. In exchange for this Husseini began to speak out in favour of Adolf Hitler and encourage Muslims to aid the Germans.
This is when Heinrich Himmler and Gottlob Berger (a key figure in the Waffen-SS) approached Hitler and said that they should use the large amount of Muslims living in Bosnia to help with their manpower shortages. A bit of background for those who are unaware of the political situation at the time. Bosnia and Croatia were controlled by a German puppet state known as the "Independent State of Croatia", they had serious problems with partisans led by Josip Tito who tied down a significant amount of German troops who had to garrison the area. The Nazi hoped that by creating these SS-Units made up of Muslim and Catholic Croats/Bosnians they could send their German units to the Eastern Front where they were needed and use the new SS-Units to fight the partisans.
The Muslims in many cases were enthusiastic to join the Germans, not only because they had been exposed to propaganda from leading Muslims like Husseini, but also because they were afraid of the Soviet Union, like many people were. In other cases though threats of violence were made to force the Muslims to join. Gottlob Berger, reportedly threatened to burn down Muslim villages if they didn't send men to join the SS.
So the Germans essentially justified it by saying "Lets relax the racial purity laws for now, so we can deal with bigger issues. Once those issues are dealt with, we can go back to fully enacting our racial laws".
Sources:
Hitler's Second Army by Edmund Blandford