When is typically an adverb, but it can be used as a pronoun, specifically a relative pronoun. It usually introduces a relative clause. Here is an example: The time when I was sick was the worst.