While the House pairings for other classes could be mostly random due to the relative safety of their subject matter, the House pairings for Potions always followed a rigid formula that had been determined over a number of generations at the cost of several classrooms. Hufflepuff would always be paired with Ravenclaw and Gryffindor with Slytherin.
The reason for these parings is thus:
Ravenclaws often tended to try to find more efficient steps or shortcuts for their potions. Paired with Gryffindors, they often became bold enough to attempt to make their theoretical methods reality, usually with explosive results of varying degrees of severity. Paired with Slytherins, Brains and Ambition often tried to outdo each-other and had often come to very messy ends.
Hufflepuffs most often steadily plowed through their work as they did every other class. It is with them that Slytherin and Gryffindor reveal their similarities, as with both pairings, the other house would often pick on the Hufflepuffs and cause an explosion by throwing a random ingredient into a Badger's cauldron when the professor who had mistakenly believed the mixture of houses to be stable let his or her guard down and was focused on some other task such as grading.
Without Bravery to try and Ambition to attempt to outdo, the theories of the Ravenclaws tend to remain theories.
Without Lions or Snakes to pick on them, the Hufflepuffs can focus on their work with little fear of it blowing up in their faces.
The pairing of Gryffindor and Slytherin - while seemingly volatile to an outside observer - is a surprisingly stable one as any competent Potions Professor knows to keep his eyes on the students at all times while they are in his classroom.