file not sorted / SO:coordinate

The tool needs the file sorted in a specific order and this one is not

why

Most downstream tools require coordinate-sorted, indexed BAM; a few (mate-fixing, some counters) require name-sorted instead. Files come out of an aligner in neither order, and the header's SO: tag is what tools check.

what to do

Sort into the order that step actually needs — samtools sort for coordinate, samtools sort -n for name — then index if it is coordinate-sorted. Sorting twice in a pipeline is a common waste; check what each step requires before adding another sort.

SAM/BAM specification
This is one entry from BioErrors, a catalogue of bioinformatics error messages that point at the wrong thing. Every entry was traced to its real cause before it was written down.
If your error is not in it, paste it there and it gets traced and added.