The theory is that it is legal because the states have a right to run their elections. I am not a lawyer so no idea but that was the talking point when our legislature was discussing it.
States can pass laws. They need ‘permission’ from Congress to enter into any compact or agreement between the states.
Each state’s legislature does determine the manner of picking that state’s electors. However, this compact could still be ruled unconstitutional, because (1) the Congress must approve of it, per the Constitution, and that has not happened yet; and (2) less than half the states could effectively overthrow the traditional method of selecting the President, as opposed to the 3/4 needed to ratify a genuine Constitutional amendment that does the same.