The U.S. Constitution does not specify procedures for the nomination of candidates for presidential elector. The two most common methods the states have adopted are nomination by state party convention and by state party committee. Generally, the parties select members known for their loyalty and service to the party, such as party leaders, state and local elected officials and party activists.

https://www.ncsl.org/research/elections-and-campaigns/the-electoral-college.aspx

While I'm not suggesting for a moment that Trump could win re-election through faithless electors (he'd need too many - at least 40 by most counts), if he did so, it would be legal (Constitutionally, at any rate). If a State wants to make faithless electors illegal, they can, but many have not. Consider that in 2016 there was a record seven faithless electors.

A historic number of “faithless” electors -- seven in total--each cast their ballots on Monday for a candidate other than the one who won his or her state. What may be more surprising, given the level of protests against Donald Trump and the pressure exerted on Republican electors, is that a greater number were untrue to Hillary Clinton than to Mr. Trump.

Among the 538 electors chosen to represent their states in the Electoral College, five were faithless to the Democratic nominee and two to the Republican. Prior to this year, there hasn’t been more than one faithless elector in any presidential election since 1948. ...

Though there is no Constitutional provision or federal law barring electors from voting for whom they are pledged, more than half of the states, including D.C., “bind” their electors. The rest of electors may have the legal authority to vote for whomever they want, but, as CBS News previously reported, faithless electors have never decided a presidential election.

https://www.cbsnews.com/news/which-candidates-did-the-seven-faithless-electors-support-election-2016/