Any law passed on this is unconstitutional.
However the political parties CAN make such rules. And the TN GOP did exactly that.
That’s because TN has open primaries. Dems could put in their own candidate and cross over to vote for him. The rules also say you had to be active in the party for a certain length of time.