‘That’ and ‘which’ are examples of relative pronouns. How these two relative pronouns are used, that is, the role that they play within a sentence, determines which of them is the correct choice.
‘That’ is used (restrictively) to narrow a category or identify a particular instance.
‘Which’ is used (non-restrictively) to add information about something that has already been identified.
Notice that the ‘which’ clause is preceded by a comma – and that whole clause could be removed, without losing the grammatical sense of the sentence.
If the ‘that’ clause of the first example is removed, what’s left is no longer true.
‘Which’ might be used (restrictively) when preceded by a pronoun: