You do need to sort the attributes in a DER-encoded SET. This is critical for CAdES which computes the hash of SignedAttributes by re-assembling them as an explicit SET before computing the digest. If you didn’t sort them the same way, the hashes won’t match.