On what grounds? The Constitution says the states have to produce electors. I don’t think it says how they have to do that.
True. What if there is a clear winner in each state, but the popular vote comes out 50.01% vs. 49.99%? Recounts will be demanded everywhere, and we'll have more "hanging chad" fiascos than we can count. Does MA want to pay for all of the recounts?
It might be legal, but I can see future elections stretching out for months of recounts while the "Popular Vote" states decide where they're going.
Suppose the majority of the voters of Massachusetts voted for the candidate that did not get the national popular vote. By giving their states electoral votes to the other candidate would disenfranchised all those voters. The voice of the voters should be heard regardless of whether they voted for the candidate who won the national popular vote or not.