Primaries are run by the states, caucuses are run by the parties. The party decides which process to use, but if it's a primary, it's run by the state. So the date of a primary is set by the state, but the date of a caucus is set by the party. And the rules of primaries are set by the state, subject to federal law, of course, hence Virginia's ballot access rule, and the subsequent lawsuit. Now why states get to run primaries - I don't know the history. But the parties like having the state run the primary, as then the party doesn't have to pay for it.