My use of the word illegal is not the right word with regard to the Ultra Orthodox Jewish belief. Their word is illegitimate. I not sure if there is any real difference between illegal and illegitimate. The point is that the Jewish belief is that the Messiah has to establish the state of Israel, not men. Others who do not accept the state of Israel, like Iran, believe that the United Nations partitioning of Palestine into a Jewish state and a Palestinian state was illegal. That discussion is for international legal scholars. My point about the Jewish population in Iran is just to establish that Iran seems not to have a problem with Jews per se but with the state of Israel; otherwise they would be rounding them up and either expelling them or killing them.
As far as the legality of various governments around the world based on human rights violations, starting wars, supporting terrorism, etc. many nations are charged with these violations (including the US as evidenced by the indictment of several U.S. government officials as war criminals in several countries in Europe under the doctrine of Universal Jurisdiction.) These violations do not seem to be the basis for determining if a government is legal.