The protection is called "luck". The probability that such an event occurs are sufficiently low that it can be neglected. Provided that the RSA keys are generated properly.
In 2012, some researchers made an interesting study in which they collected 11.5 millions of publicly available RSA keys (e.g. keys from SSL server certificates). They found that some keys were widely duplicated (my own sampling found the same: apparently there are widely deployed ADSL or cable modems that host a SSL server, all with the same public/private key pair). They also found, and that's what corresponds to your question, that factor sharing between distinct RSA keys was rare but not unheard of. This demonstrates use of a poorly seeded PRNG.
Indeed, any practical RSA key pair generation will produce random primes by running a PRNG seeded with some "initial randomness". If that initial random seed has not enough entropy, then the number of possible primes that this generator may produce is low. For instance, if the seed has 40 bits of entropy, then it suffices to generate a million RSA keys or so to obtain a collision (two of these keys using a common prime factor). More generally, if the seed has entropy n bits, then everybody should be safe as long as less than 2n/2 RSA keys are generated. Proper PRNG will aim at n = 128 or more.
While there is no need to fear such an outcome with properly generated RSA keys, this fact illustrates that adequate PRNG seeding is not easy, and, crucially, it is very hard to ascertain whether a given seeding process is adequate or not. Some embedded systems, and virtual machines, are most at risk of not having enough "physical" entropy to work with.