In this context, 'when' is used as a conjunctionand means the same as 'if'. They can be used interchangeably.
— used to say what happens, is true, or can be done in a particular situation
When you have no family, you are really on your own.
We take the bus to school when it rains.
A contestant is disqualified when she disobeys the rules.
When and if he comes, you can ask him. = If and when he comes, you can ask him.
— used to ask why or how something is done in the situation that exists
Why buy a newspaper when you can read the news online for free?
How can he buy the house when he has no money? [=he has no money, so how can he buy the house?]