What determines the case position of «الَّذِي»?

Relative Nouns — Ṣilah, ʿĀʾid, Forms and Syntax