This plugin can prevent deletion of elements (entries, assets, categories, products and users) if they are referenced in other elements.
The idea is taken from the plugin Restrict Asset Delete, improved to apply to all elements, and made Craft 4/5 ready.
composer require ryssbowh/craft-restrict-deletions:^3.0