Is "He told me not to argue but just agree." grammatically correct?
The infinitive to is not dispensed with in the second instance of the sentence.
It is just omitted, to be understood by the reader. This is known as ellipsis.
So the two forms of the sentence are identical, technically and semantically.
Both of them are correct.
[Edit] Pl. read in conjunction with my comments below re: and / but.
It might be interesting that only the first of your alternatives would have been considered correct in traditional formal grammar. In the final two ('... but to just agree' and '... and to just agree') you have split the infinitive, i.e., you have separated the word 'to' from the verb stem 'agree'. While that is not generally considered grammatically incorrect these days, one might instead say, 'He told me not to argue, just to agree' (I have also removed the problematic 'and'/'but' decision).
P.S. This was just a comment, but due to popular support I added it as an answer.
The simplest and clearest is "He told me not to argue but to just agree."
The reason that this is simplest is that it is the easiest to parse without ambiguity:
["He told me"] -> ( (("not to") ["argue"]) / (("but to") ["just agree"]) )
That is, "do this not that".
The split infinitive is not considered an error in current usage.
All of the formulations using "and" are open to the ambiguous interpretation
He told me not to argue [with someone about A] and [also] to just agree [with someone else about B].