Hashem says (Bamidbar Rabba 21:22 in reference to Shemini Atzeres), "קשה עלי פרידתכם". The Imrei Noam translated it, "It is painful for me when there is machlokes and division amongst you. It is especially painful for Me when the machlokes is עלי, about Me. When you claim you are fighting for My honor."
Throughout the history of the Jewish nation, there were many disputes — among individuals and communities – and the motives were often the preservation and continuity of Yiddishkeit and to stand up for Hashem's honor. At times those fights were indeed important, and due to those disputes, our adherence to Torah and mitzvos continues to the present day. However, there were many times when people thought they were fighting leshem shamayim, but it was really just the yetzer hara.
Likely, Korach thought his ambitions were altruistic, that he was fighting for Klal Yisrael's honor or his own spiritual growth. Had he looked closer he would discover that behind his machlokes was jealousy and a drive for honor. He would have discovered that what he thought was righteous indignation was the yetzer hara.
The Baal HaTanya writes, "Most tzaros come from machlokes 'leshem shamayim.' May Hashem save us from them" (Igeres HaKadosh 56). Consequently, whenever you're about to create a machlokes "leshem shamayim," be cautious. Realize that you may be mistaken. Give yourself time to think things over and to check things out. Often, jealousy, hatred, or some other bad middah lurks at the root of your urge to make machlokes.
Kayin and Hevel had a dispute, which ended with Kayin killing Hevel. What was the disagreement about? The Midrash (Bereishis Rabba 22:7) states two opinions. One is they were debating on whose property the Beis HaMikdash will be built, each wanting the Beis HaMidash on their property. A second explanation is that they were arguing about the earth; who owns the land, its elements and substances. "Kayin and Hevel said, 'Let's divide the world between us' [and they did so]: One owned the land, and the other became the owner of all mitaltelen (elements/substances). The landowner said, 'you are standing on my land!' "The other replied, 'And you are wearing my clothing. Remove the clothes.' "'And you must fly [in the air].'" This was the spirit of the dispute, which ended with murder.
Baalei mussar say that both explanations of the Midrash are telling the same story. Their real intention in the machlokes was about wealth, land ownership, and resources. But they were ashamed to fight over such petty issues, so they fought over who would host the Beis HaMikdash. But the core of the machlokes was money.
Reb Yohonasan Eibshitz, zy'a, (Yaaras Dvash, drush 8) writes, "With every machlokes, the yetzer hara assures us that our intentions are purely leshem shamayim, and chas veshalom to even suggest otherwise! So, how can we recognize whether a machlokes is leshem shamayim or not? This is the test: If both parties love each other with all their heart and soul aside from the issue they are arguing about, that is a sign that their argument is leshem shamayim. However, if they harbor hatred towards one another, the machlokes isn't leshem shamayim. The Mishnah hints to this when it states, איזו היא מחלקת שהיא לשם שמים, which can mean, how do we know that a machlokes is leshem shamayim? The answer is, זו מחלקת הלל ושמאי, if it is similar to the machlokes of Shamai and Hillel, for Shamai and Hillel loved and honored each other. This proves that their machlokes was leshem shamayim. But Korach and his followers harbored animosity towards Moshe. They almost stoned him. This proves that their dispute wasn't leshem shamayim. With this test, one can know whether his intentions are leshem shamayim or not."
The Bnei Yissaschar zt'l gives us another sign to help determine whether your motivation is leshem shamayim or jealousy. Generally, when fighting with "religious indignation" one’s emotions are passionate. He feels like an exploding volcano, ready to knock down all people who are going against Hashem. Therefore, he should gauge himself and see whether he possesses such frenzy when performing a mitzvah, such as tallis and tefillin, succah, helping the poor, etc.? If this passion surfaces only by machlokes, that's an indication that he's inspired by the yetzer hara, not the yetzer tov.
The Imrei Noam zt'l taught that the worst sins could be committed when one thinks he's motivated by spirituality. No G-d-fearing person would think of destroying someone's parnassah or his life. But the yetzer hara convinces a person that he must take a stand to avenge Hashem's honor or to preserve Yiddishkeit, and so on, so he must fight with an individual or a community. And now he is liable to do sins he would never consider doing otherwise. If he is wrong, and Hashem doesn't want the machlokes, then he is taking Hashem's name and using it as a powerful weapon to do terrible things.
The Imrei Noam writes that this is hinted by the words, יצרו של אדם מתגבר עליו כל יום ואלמלא הקב"ה עוזרו לא יכל לו (Succah 52:). This can be translated, if it weren't for the yetzer hara's claim that it must be done for Hakadosh Baruch Hu's honor, לא יכל לו, the yetzer hara couldn't have convinced the person to do such awful deeds.
Another problem with a machlokes leshem shamayim is that such a machlokos can last a very long time. This is because the instigators don't repent, for they think they're acting righteously. While a dispute over mundane matters can be resolved over time, when Hashem's name is involved, it can last forever. This is hinted at in the following Mishnah (Avos 5:17): "כל מחלוקת שהיא לשם שמים סופה להתקיים, A dispute that’s leshem shamayim will last. ושאינה לשם שמים אין סופה להתקים, but a dispute that isn't leshem shamayim, won't last."
There is a machlokes on how to pronounce אדנ"י, whether the emphasis is on the 'ד or the 'נ. Once, when this was being hotly debated, the Noda b'Yehuda commented, "Hashem says, 'My name that was written in holiness should be erased for the sake of peace.' Peace is more important to Hashem than His name. Surely Hashem doesn't want you to fight over the pronunciation of His name."