John Lawler wrote:
That, as a relative pronoun (We know the man that she saw), or as a complementizer (We know that she saw him), occurs only in tensed clauses, which are otherwise independent, except for the machinery involving that.
...
The question of which wh-words can be swapped with that is difficult and varies a lot from person to person. Most English speakers wouldn't notice if that were used instead of when, since it can be used for where, why, and how. But some folks prefer when and disprefer that in this situation.