The network can't tell the difference. In the astronomically unlikely event that two different people have private keys whose public keys hash to the same public address, then both of them are able to spend any coins sent to that address, first-come-first-served.
To illustrate how unlikely this is: suppose every satoshi of every bitcoin ever to be generated was sent to its own unique private keys. The probability that among those keys there could be two that would correspond to the same address is roughly one in 100 quintillion.
Of course the probability is only "astronomically unlikely" if the private keys are truly randomly generated. If they are not, then there can be better chance of someone else being able to guess the private key. Anyone who does so can spend coins sent to that address. That was what happened with this vulnerability.
A fun activity, analogous to "leave a dollar bill on the street and see who picks it up", is to make yourself a private key that is a very small integer. Then send some trivial sum of money to the corresponding address. There seem to be a number of people watching such addresses so you can see who manages to grab it first (by spending it to a more secure address they control).