Surely this would be struct down by the current Supreme Court if it shifted the outcome of the election from Trump to the Democrat.
Why? States are allowed to choose their EC members under Article II, Section 1, Clause 2 of the Constitution:
Doesn't say anything about having to abide by the popular vote winner of the state in question.
If the state legislature wants to
They also aren’t allowed to join compacts with other states
States reach agreement with one another all the time without there being a Congressionally approved compact.
Virginia v. Tennessee, 148 U.S. 503 (1893), held that only those compacts that increase the powers of the States relative to the Federal government need approval.
There's also
McPherson v. Blacker, 146 U.S. 1 (1892) which held explicitly that Congress' authority to set the time of selecting electors does not give it any authority to determine the manner in which they are selected. (Bizarrely, for the 1892 election Michigan was divided into an Eastern and Western District which were each composed of six congressional districts. Each congressional district, the Eastern District, and the Western District each elected one elector, so each voter got to vote twice for elector, once at the Eastern/Western District level and once at the congressional district level. Michigan ended up with 5 Cleveland and 9 Harrison electors.)
McPherson also held that the Fourteenth Amendment didn't require a popular vote for Electors.