You asked me what the code should do with the subnets when the shared network is being deleted. I updated the CB design doc: https://gitlab.isc.org/isc-projects/kea/wikis/designs/configuration-in-db-design#remote-network4-del
with two variants that differ by "subnets-action" parameter. We need to add support for this parameter to explicitly control whether the subnets are kept or deleted. This idea is derived from the subnets_cmds hook and I believe that's the best option here too.
Note that the variant that removes a shared network but keeps subnets requires to update shared_network_name column for all these subnets to null. Perhaps the easiest way to do it via an SQL trigger.