If they made a setting at the start of the game as to how many party members you wanted, then all the encounters would be based off of that. If you want a 4 party team, great! The CR and number of creatures you encounter would be based off of that. If you wanted 5 or 6, then the CR scale would slide based off of that.
That might be the ideal design, but a huge problem is that it would require much more play testing and balancing than designing encounters for a single maximum party size.
Each different party size would require either a change in how powerful each enemy is, or how many enemies are in the encounter. And then every permutation would need testing and balancing. That's a lot of work, if the goal is to make each party size have the same amount of challenge. Which is why most games don't do this.
Alternatively, they just divide exp between characters that participated in the fight. This self corrects, at least to some degree. -Party of 6? They'll all be individually weaker -Party of 3? They'll all be higher level
Do characters that aren't in your party gain experience? For this, we can look to Dragon Age: Origins, where party members left at camp were autoleveled to never be more than 1 level below your main character. This prevents cheese where you get a whole bunch of characters at high level by doing a lot of 2-person fights, but also prevents characters you don't typically take with you from being too low level.