Sexual reproduction started with some reciprocal exchange of genetic material between similar individuals. But later organisms had to deal with the problem of inbreeding depression. As a result of this, a mechanism that ensures that sexual reproduction occurs only between unrelated cells, was evolved. In essence, fusing with unrelated cells ( cells with different surface chemistry ) avoids inbreeding depression.In most species, only two types of individual occur with respect to their surface chemistry.But, if the reason for evolving different mating types is to avoid inbreeding, why are there just two mating types?

If you look at evolutionary trends in general, efficiency and simplicity in any given situation often wins. If there were more than two genders, that would create too many possible permutations of mating relations for mating to really be efficient. What if one gender could mate with two others, but one of the two others could only mate with one other. Biochemically that would be very complicated.

A maximum of two sexes was likely just the simplest, most efficient way to breed safely.