Can I install a device transformer in a junction box to keep it behind the wall surface?
As long as you have the high voltage separated from the low voltage and you do not over fill the box it would be legal as long as it is accessable, I use deep 4 square boxes with a blank cover plate regularly to encase small camera power supplies and I have not had any code issues in Lynn, Benton, or lane counties.