Boundary layers for the subcritical modes of the 3D primitive equations in a cube