If you want this to work only on specific magic glass, this cannot be done with shaders and is very difficult and time consuming with render layers:
shaders have no clue which glass it is looked through, it reacts to all of them or none of them.
render layers have problems with refraction and transparency and influencing other (background) objects if the xray material emits light. Also intersecting x-ray objects with non-xray are a problem. The materials setup for them are complicated and dependent on object indexes and worth a separate answer if you want to know. It's basically setting 2 render layers to output the same as below.
The solution is to use multiple scenes:
- 1st one normal
- 2nd one duplicate with all "x-rayable" objects having x-ray shader
Then you just composite them together through a mask from the magic-glass. So the magic glass is like a portal window to an alternative world with x-ray objects:
Oh no! There are Suzannes trapped inside those spheres.
To save some time rendering you can make use of adaptive render region addon in the 2nd scene and render only around the magic-glass object.
Also if there is no visible light (direct or indirect) coming through or reflected off the magic-glass into the 1st scene, it's good to give it just plain black or holdout shader, so it renders faster. It will be replaced with the 2nd scene anyways.