Can NM cable run directly behind a junction box in a wall?
The only two things that come to mind are that a box must be set at an appropriate depth so that it rises to the surface of the final wall covering, and that NM-B cable must be protected by a nail plate when it passes through framing within 1.5&quot; of the edge/surface.
If the wire-behind-box arrangement were done in a 2x4 wall there could be a problem. It appears your wall stud is 2x6 though and provides enough room to satisfy both of those constraints. I think your work looks fine.
All that said.. you could've drilled a new hole above or below the box with a spade bit in about 4 seconds. Of course that would have let the opportunity to ask a question and learn something new slip by. :-)