〜るとき/〜たとき(従属節の時制)
Whether とき takes the dictionary form or the た-form depends not on the sentence's overall tense but on whether the clause's action is complete at the moment of the main action. 日本へ行くとき、かばんを買いました = I bought the bag before arriving (on the way); 日本へ行ったとき = I bought it after arriving, in Japan. Dictionary form + とき = before/during; た-form + とき = after. A classic N4 exam point.
日本へ行くとき、空港でかばんを買いました。
When I was on my way to Japan, I bought a bag at the airport.
日本へ行ったとき、着物を買いました。
When I went to Japan (after arriving), I bought a kimono.
寝るとき、「おやすみなさい」と言います。
When going to bed, we say 'oyasuminasai'.