Foreign medical graduates who scores above 65-70th percentile have no problem getting into residency programs (I've made a comment above with more details as to how I know all this). For a green card holder, you just need to get ~60th percentile of the USMLE score (which translates to about 240+ in step 2 CK and step 3 USMLE scores).
All I wanted to say is that the bar isn't too high for a US citizen to get into a residency. That doesn't mean though that the path to get into residency is easy. It is extremely convoluted and requires a lot of persistence and planning. That's where (along the way) people fall through the cracks.
But yes, also a small number of people just don't have the intellectual ability to handle it, although schools do a lot of screening to minimize this. Graduation rates at schools are typically 100%, with maybe 1 person every other year failing out.