What does it take to get a tenure track position at an Ivy League School?
The Ivy League is an athletic league, not a list of the top universities.  They are all very good, and some of them are great, but nobody thinks UPenn is more prestigious or a higher-ranked university than Stanford (despite the fact that UPenn is in the Ivy League and Stanford is not).

Furthermore, the strength of individual departments is correlated with the overall prestige of the university, but there's a lot of variation.  The prestige of the university plays some role in recruiting faculty, but departmental strength is the primary factor.

Finally, schools really shouldn't (and generally don't) care much about the pedigree of the candidate.  They are much more interested in accomplishments than educational background.  Of course, there's a strong correlation between accomplishments and pedigree, for at least two reasons.  Talented, ambitious students are likely to have the opportunity to attend top schools, and they often take that opportunity.  Once they are there, they benefit from an environment full of top faculty and other students like them.  So it's no surprise that many professors at top schools studied at such schools themselves, but they didn't all do so.

As for what other factors come into play, that's a very broad question.  At top research universities, the big question is how good your research is, primarily judged by external letters of evaluation.  There's nothing special about getting a job at a top school, beyond the degree of competition.

Regarding the Ivy League students who end up teaching at lower-ranked universities, that's numerically guaranteed.  Every research university graduates more Ph.D. students than it hires, and typically far more, so there's no way they could all get jobs at schools like the ones they attended.  (But keep in mind that most colleges are not research universities and do not offer Ph.D. programs.)  To a first approximation, most Ph.D. recipients from top universities will get jobs at lower-ranked research universities (or other types of jobs entirely, for example teaching-focused or industrial).  Most students from lower-ranked research universities will not get jobs at research universities at all, although of course they may still end up in academia.