Apple - 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 -batteryallowed flag:

hdiutil compact my.sparseimage -batteryallowed 

You may need to run the command as root :

sudo hdiutil compact <sparseimage>