So basically, Electors are chosen by state legislators. Normally, they follow an established rule within each state that's tied to the popular vote. It varies from state to state, but it's normally something along the lines of a percentage of Electors vote according to the proportion of the popular vote won by each candidate
or whoever gets the most votes gets all the Electors. There's a deadline between the end of the popular election and the
actual Electoral vote. They don't happen at the same time. The state legislatures can, if they so choose,
toss out the results of the popular vote and choose Electors based on whatever criteria they want, who will vote for whoever they want. All they really have to do is claim the popular vote is illegitimate for some reason. Like, say, fraud.
This allows the state politicians to throw out the actual election results of their states. It's what rxrx mentioned. And is apparently something that the GOP and Trump campaign have been discussing, should he lose the Red swing states.
Here's the
article rx was talking about.