Each State shall appoint, in such Manner as the Legislature thereof may direct, a Number of Electors, equal to the whole Number of Senators and Representatives to which the State may be entitled in the Congress: but no Senator or Representative, or Person holding an Office of Trust or Profit under the United States, shall be appointed an Elector.The manner of choosing who gets the state's electoral votes are entirely up to the legislature. They could entirely dispense with having people vote for president and have the state legislature pick who gets the votes, if they feel like it.
BUT, once they have made a rule on how to choose electors, they MAY NOT change the rule after electors are chosen. United States Code, Title 3 chapter 1
Determination of controversy as to appointment of electorsParagraph 2 of the above US Code also prescribes that if electors are not chosen by election by the deadline (say, because civil unrest has disrupted elections), then the legislature may choose who gets the electors.§ 5. If any State shall have provided, by laws enacted prior to the day fixed for the appointment of the electors, for its final determination of any controversy or contest concerning the appointment of all or any of the electors of such State, by judicial or other methods or procedures, and such determination shall have been made at least six days before the time fixed for the meeting of the electors, such determination made pursuant to such law so existing on said day, and made at least six days prior to said time of meeting of the electors, shall be conclusive, and shall govern in the counting of the electoral votes as provided in the Constitution, and as hereinafter regulated, so far as the ascertainment of the electors appointed by such State is concerned.
However, if a state decides to ignore their own voters and choose a different candidate for any reason, I think it would be quickly challenged under the Voting Rights Act. A