A layer may only be deleted if it is not referenced by any entities (graphical or non-graphical), as such, you'll need to iterate over the drawing database (including entities nested within all block definitions and also AcDbBlockBegin entities), and either reassign or delete those entities which reference the layer, before deleting the layer definition itself.