Which the 10th and 12th Amendments allow them to do. Since the 12th Amendment doesn't say how the electors are selected then the 10th Amendment gives the states the power to select the method. So sure, states can go winner-take-all, they can divvy them up by congressional districts, they can do what South Carolina did until the Civil War and give the legislature the power to decide. But regardless of how they do it it's not the court's place to say that their method has to be changed.
Some people would like to see them assigned proportionally. (For example, Maryland has 10 electors. if Trump gets 40 percent of the vote, he gets 4 of 10 electors, and the crazy person running against him gets the other 6.)
Bad idea, I think, and it somewhat undermines the function of the Electoral College, but states are free to do that too, if they choose.
You don’t really need the 10th or 12th amendment to establish this, although they certainly do so. The Constitution explicitly gives the states the right to determine how their electors shall be chosen.