Declarations aren't "run" - they're not something that needs to execute, they just tell the compiler the type of a variable. (An initializer would run, but that's fine - you're not trying to read from the variable before assigning a value to it.)
Scoping within switch statements is definitely odd, but basically the variable declared in the first case
is still in scope in the second case
.
From section 6.3 of the JLS:
The scope of a local variable declaration in a block (§14.4) is the rest of the block in which the declaration appears, starting with its own initializer and including any further declarators to the right in the local variable declaration statement.
Unless you create extra blocks, the whole switch statement is one block. If you want a new scope for each case, you can use braces:
case 1: {
int y = 7;
...
}
case 2: {
int y = 5;
...
}