In this particular case, live in is not the sort of construction which most grammarians would call a phrasal verb. The preposition here cannot move forward: you cannot say ✲The students lived the house in. So The students lived in the house does not have a different sort of sense than The students lived by the river or The students lived on the beach. In the house is simply an ordinary prepositional phrase, an adjunct modifying lived.
In these circumstances, all we're dealing with is the ordinary rule of pied piping:
RULE
When the object of a preposition is replaced or modified by a WH- relative pronoun that is ‘fronted’ (moved to the head of its clause), the preposition may be moved with the WH- word.
Note that 1) this is true only of WH- relatives, not that or the ‘zero’ relative, and 2) it may be moved, not must.
Generally, formal contexts require that the preposition be ‘pied-piped’—moved to the front—while colloquial contexts tend more to ‘strand’ the preposition—to leave it in place after the verb. This is not a rigid distinction, however; corpus studies have shown that even in speech pied piping tends to be employed more than is generally asserted. Here is a long but very interesting study.
Slightly different rules apply with true phrasal verbs, as you may read here.