This is a great question. Here's my take on it:
Towards the end of Season 1, Ned Stark is arrested in King's Landing. Incensed by this, Robb raises his bannermen to march on the South. When Ned is killed, he reaches a point of no return and vows revenge.
Then, in the Season 1 finale Fire and Blood, we hear this speech:
Robb: Renly is not the King.
Other Character: You cannot mean to
hold to Joffrey, My Lord. He put your father to death.
Robb: That doesn't
make Renly King. He's Robert's youngest brother. If Bran can't be Lord
of Winterfell before me, Renly can't be King before Stannis.
Other Character: My Lords. If we
put ourselves behind Stannis ...
Jon Umber My Lords! Here is what I say to these
two Kings [spits] Renly Baratheon is nothing to me, nor Stannis neither.
Why should they rule over me and mine from some flowery seat in the
South? What do they know of the Wall or the Wolfswood? Even their Gods
are wrong! Why shouldn't we rule ourselves again? It was the Dragons
we bowed to and now the Dragons are dead! There sits the only King I
mean to bend my knee to ... the King in the North!
Now, there's something very important revealed in this speech. Or rather not revealed. Robb intends to march on the South to fight for his father and the North. At no point is it shown that he is aware that Joffrey is a false King.
Instead, he simply thinks there are two other claimants for the throne and he wants nothing to do with it - he just wants revenge. Why would he swear a claim to Stannis, who has no chance to rule the throne? It's Joffrey's by right - as Robb mistakenly thinks. Based on this, and his bannermen's support, he declares himself King in the North.
Even Stannis only becomes aware of his true status of King in the Season 2 opener, The North Remembers, when Ned's letter arrives.
A few episodes later, in What is Dead May Never Die and Garden of Bones, Lady Catelyn actually arrives at the camps of both Renly and Stannis to try to negotiate a peace between them. However, by this stage Robb's claim as King in the North is well known. And Stannis will not back down from being King over the whole kingdom. As he tells Catelyn:
Stannis: It is strange to find you beside my brother, Lady Stark. Your husband
was a supporter of my claim. Lord Eddard's integrity cost him his
head. And you sit beside this pretender and chastise me. We share a
common enemy. The Iron Throne is mine by right. All those that deny
that are my foes.
At this point, despite her attempts to broker some sort of peace between Stannis and Renly, he is beyond redemption. Pride, desire to rule the whole kingdom and the Red Priestess mean he will not negotiate and thus Stannis and Robb become enemies, albeit ones who never meet on the field.
Of course, it could still be argued that Robb could renege on his desire to become King in the North, but with an army of bannermen behind him wanting freedom, this would be no easy task and would likely lead to further conflict with Stannis down the line. Not to mention Stannis, being the type of person who remembers wrongdoing (see: Ser Davos' fingers), would likely punish them after the war was over for their attempted uprising.