They knew that they were destined to become a great nation (Bris Bain Habesarim) and the brochos of Avraham, Yitzchak, and Yaakov. They felt that Yosef (with his dreams of rulership) was going to destroy this and was to them what Eisav was to Yaakov.
As a court, they felt that Yosef was actually chayav misah and that they had actually shown him mercy by selling him away from the family.
They therefore felt that Hashem would approve of their actions (see their reactions when they finally realized that they were wrong).
Rashi says that "Habor Raik vein bo mayim" means that snake and scorpions were in this. This means that when Reuvein talked them into putting him there, they were leaving it up to Hashem whether or not he actually deserved the death penalty. Rabbi Etshalom says that the brothers themselves did not sell him to the caravan. When Reuven came back to rescue him, and did not find him, the brothers did not know what had happened. He states that they realized that the international caravan that they saw was quite a distance away. They then went out of sight of the pit so to eat and so as not to be aroused to pity. When they found that he was gone, they realized what must have happened (that a local caravan going to meet the international caravan had pulled him out). This meant that Hashem had arranged for it to happen and that they had been correct in their judgement.
Rabbi Shmuel Goldin's Unlocking The Torah Text also brings up this point and cites meforshim like the Rashbam and Rav Hirsch.
The Art Scroll Bereishis page 1650 goes into detail on the various arguments of "Who sold Yosef?"
Hashem knew that Yosef's trials and troubles in mitzrayim were necessary for him to grow into the tzadik and powerful leader that was necessary.
Part of what Hashem told Yitzchak was that it was necessary and that this was a private nevua (not to be told to other people). We see from other discussions that a nevua can only be made public when Hashem commands. See the commentaries on why it says "Hashem said to Moshe, Laimor" (that is Moshe was commanded to reveal the nevua). Thus Yitzchak knew that he was not allowed to reveal the truth to anyone, no matter how much it hurt him to do so.