I don't understand how any state can do that because you can vote for anyone you choose, all you have to do is write in the name.
You can write it in, but “they” don’t have to tabulate it.
>> I don’t understand how any state can do that <<
Try reading the U. S. Constitution, where it says that the states’ legislatures are the sole authorities for determining how electors for the POTUS are chosen.
Basically, the state legislatures can set up any set of rules they want — other than maybe to rule that blacks, other ethnic minorities, homosexuals and females can’t be electors.