I wish I understood why the state runs a primary election. That seems like it should be the responsibility of the party to decide who their nominee is. Should be their own rules, and cost
I agree that it makes sense in the abstract that ostensibly private organizations conduct themselves as they see fit. But in the U.S. the practical reality is that the Democratic and Republican Parties are effectively official institutions. If voters' only input was to choose between two people secretly selected by these organizations, it wouldn't be very democratic. And imagine that happening in the many U.S. voting districts where the same party always wins - it would be completely undemocratic.
On the other hand, IIRC my history, before maybe the 1970s the U.S. parties did use more private processes, selecting candidates in the 'smoke-filled room' (the image is of fat old men smoking cigars and making deals). Some say the quality of candidate was better then.
Some states they do. In my state, the Democrats hold caucuses instead of primaries (even though the state runs primaries anyway—weird story), and I think at their own expense. Running an election is a pretty big operation (you need to register voters, check that they're eligible, set up and staff either polling places or mail-in sites, and so on. The state already has most of that infrastructure, and it seems wasteful to duplicate it. I don't know for sure, but I wouldn't be surprised if some (or all) primary states allow third parties to register to have their primaries run as well.