Enabling depth buffer

When I enable depth buffering, all objects are in the correct place when rotating around the Z axis, but when I rotate around the X axis, the objects overlap. If I do not enable depth buffering, the objects are in the correct place when I rotate the X axis, and they overlap when rotating the Z axis. Any ideas how to resolve this?

Thanks