When compacting a sparse image with the
hdiutil compact command, it fails with the message hdiutil: compact failed – Function not implemented.
The error message is pretty unclear, but one reason might be that you are not connected to the power outlet. Compacting a disk image might be a long and intensive task, and sometimes the OS denies it when you are running on battery to avoid any risk of data loss.
If you are positive that you have enough battery power to complete the task, you may overrun the limitation by adding the
hdiutil compact my.sparseimage -batteryallowed