The DNC and RNC are legally bound to follow rules established both by state law and by Congress/legislation. Yes they are private institutions but they can not set arbitrary rules.
The rules set by state law and Congress for candidate selection offer a pretty wide berth in terms of methodology for selecting which candidates appear on the ballot. There's no (federal) Constitutional mandate for primaries; procedures for how a state selects its presidential electors are up to the legislators of each state.
When it comes to their primaries, the only obligation that they have to is to follow their own rules, and the only people that are allowed to hold them to that obligation are they themselves, and maybe their vendors.
They aren't even obligated to donors who donated under the assumption that there's some promise or legal requirement that their primaries be fair. That case was dismissed, and resulted in the quote from DNC lawyer Bruce Spiva:
"You know, again, if you had a charity where somebody said, Hey, I’m gonna take this money and use it for a specific purpose, X, and they pocketed it and stole the money, of course that’s different. But here, where you have a party that’s saying, We’re gonna, you know, choose our standard bearer, and we’re gonna follow these general rules of the road, which we are voluntarily deciding, we could have — and we could have voluntarily decided that, Look, we’re gonna go into back rooms like they used to and smoke cigars and pick the candidate that way. That’s not the way it was done. But they could have. And that would have also been their right, and it would drag the Court well into party politics, internal party politics to answer those questions."