Here is the root cause, which is failure to follow the 1961 instruction, “RELIGIOSORUM INSTITUTIO”, by Pope John XXIII:
“Advantage to religious vows and ordination should be barred to those who are afflicted with evil tendencies to homosexuality or pederasty, since for them the common life and the priestly ministry would constitute serious dangers.”
I doubt that those with "evil tendencies to homosexuality or pederasty" are advertising the fact. So how are those ordaining them supposed to know?
It seems to me that one of the best tests of this is: Does the man have a wife and a normal family?