Depth data works, but not in Background mode
Rendering of viewer nodes and previews in background mode was disabled in 2013 for speed optimization (see here). However, you can easily enable it again by modifying 2 files of the blender sources and compiling blender yourself (as described here).

In the file source/blender/compositor/operations/COM_ViewerOperation.h, line ~58:

bool isOutputOperation(bool /*rendering*/) const { if (G.background) return false; return isActiveViewerOutput();


should be changed to

bool isOutputOperation(bool /*rendering*/) const {return isActiveViewerOutput(); }


and in file source/blender/compositor/operations/COM_PreviewOperation.h, line ~48:

bool isOutputOperation(bool /*rendering*/) const { return !G.background; }


should be changed to

bool isOutputOperation(bool /*rendering*/) const { return true; }


After these changes, the pixels array gets properly updated in background mode.