On my digital piano the headphone jack is at the back which is impractical. Is there any jack device that can be plugged without cutting the sound, for example with a switch, so I can pull an extension to a more convenient place to plug headphones?
The sound switches off when you insert a plug into the headphones socket, due to switches built into the socket. This is what that looks like:
The plug pushes those contacts apart. The only way to prevent that would be a custom plug that is designed to work with the specific socket design in your keyboard. Not an easy fix.
If the keyboard has line outputs, you could connect a headphones amplifier to them and use that instead.