How can I install an electrical panel when the stud cavity is too narrow?
The common solution is to attach a piece of plywood larger than the panel to the studs, and then attach the panel to the plywood. This also provides a good place for attaching cables, so you can get a nice organized installation. 

 

Additionally, this technique provides the benefit of being able to insulate behind the panel.