There are several set theories, e.g. ZFC and NF, which often have different axioms or are even outright contradictory. And yet most of other branches of mathematics, e.g. abstract algebra or topology, even though they use the concept of set, can work in any of these theories. How is this possible?
Why isn't abstract algebra based on ZFC be different than that based on NF, even though they both have different set axioms?
It is not strictly true that mathematics turns out the same in both theories. For instance, since NF refutes Choice, and it's unclear if something like the Ultrafilter Lemma is consistent, the Completeness Theorem for first order logic is not known to be provable in NF or any of its extensions. There are categories $\mathcal{C},\mathcal{D}$ that are "small" in the traditional sense, but for which the functor category $\mathcal{D}^\mathcal{C}$ is not an exponential. Not every group can be the quotient of a free group. And moving to NFU, which can support Choice and easily be extended to match ZFC in consistency strength, doesn't fix all of these examples.
But note that there's a theory called KF which is axiomatized by extensionality, pairing, union, power set, and a scheme of stratified $\Delta_0$ separation. KF+"There is a Dedekind infinite set" (we'll call this "KFI") is pretty weak, but strong enough to talk about a pretty surprising amount of arithmetic and analysis. Now observe that KFI+"There is a universal set" is NF; and KFI+Regularity+Full Separation is, more or less, Zermelo. The fact that both theories are extensions of a common theory which is adequate to a good deal of ordinary mathematics should make it clear why they agree so well on the basics, even when the extensions are incompatible.