Writing a compressed texture to the KTX format with libktx 1.0.1 will always fail due to the following code in ktxWriteKTXF():
if (header.glTypeSize != sizeofGLtype(header.glType))
According to the format standard a compressed texture shall have a glType value of 0 and a glTypeSize value of 1. The combination of values will always fail the test above.
Removing the check and replacing it with the following one *after* compression has been detected should do the trick:
if (!compressed && (header.glTypeSize != sizeofGLtype(header.glType)))