If you know why both of these sentences are correct, you aren’t confused by that and which.
1. It was a bad mistake, which you knew when you made it.
2. It was a bad mistake that you knew when you made it was a bad mistake.
If the different uses of that and which are unclear, we should talk about the special cases for using these relative pronouns.