We’ve learned that when とき is modified by a plain-form predicate it refers to the time that is described by the predicate. Because とき is a noun, it can take any particle that a noun can take.
さびしいときや疲れたとき、いなかを思い出す。
I think of home when I’m lonely or tired.
生まれたときから、ずっと大阪に住んでいます。
I’ve been living in Osaka ever since I was born.
田中さんが来たときの写真です。
This is a photo of the time Tanaka-san came.