Addendum to @bogovicj’s answer:
If you have access to cplex, you can also download this plugin for section order correction and follow the build instructions to add it to your Fiji. This method works for arbitrary permutations of your sections, the method from @bogovicj’s answer only works only if the sections are out of order within a local neighborhood (the extent of local depends on the image data and how fast pairwise similarity decays as a function of distance). It is, however, more robust against noisy similarity measures. You might want to try both and pick the better result, or a combination of both, as described in the paper referenced by @bogovicj : Run the section-sort plugin first to get the sections in (approximately) correct order, then run the z-spacing plugin to correct for ordering mistakes that could not be resolved due to noisy similarity measures.