How can I reliably determine the slice order in the K (axial) dimension, regardless of the input format?
You cannot do this independently from the input format, because for DICOM images this may be impossible. Each slice in a DICOM series has arbitrary orientation: they don’t have to be parallel, they can intersect each other, you can even have many slices at the same spatial position.
Many software packages can reconstruct regularly spaced 3D Cartesian volumes from the arbitrarily set of DICOM image slices. This operation may be a simple ordering of the slices, or it can be a complex non-linear reconstruction if the slices are irregularly spaced, tilted, or not parallel. The result of the 3D reconstruction is a voxel array and a homogeneous transformation matrix that maps between IJK indices of the array and the anatomical coordinate system. All you need to interpret the image data is this transformation matrix.