They make box extenders (an example is depicted below) that can be used to extend boxes to meet the finished surface.

The 2014 NEC says...
ARTICLE 314
Outlet, Device, Pull, and Junction Boxes;
Conduit Bodies; Fittings; and Handhole Enclosures
314.20 In Wall or Ceiling. In walls or ceilings with a surface of concrete, tile, gypsum, plaster, or other noncombustible material,
boxes employing a flush-type cover or faceplate shall be installed so
that the front edge of the box, plaster ring, extension ring, or
listed extender will not be set back of the finished surface more than
6 mm (1⁄4 in.). In walls and ceilings constructed of wood or other
combustible surface material, boxes, plaster rings, extension rings,
or listed extenders shall be flush with the finished surface or project
therefrom.
This might also be relevant.
406.4 Receptacle Mounting. Receptacles shall be mounted in boxes or assemblies designed for the purpose, and such boxes or assemblies
shall be securely fastened in place unless otherwise permitted
elsewhere in this Code.
(A) Boxes That Are Set Back. Receptacles mounted in boxes that are set back from the finished surface as permitted in 314.20 shall be
installed such that the mounting yoke or strap of the receptacle is
held rigidly at the finished surface.