After discovering this same issue, I'd suggest to try to implement some prevention checks on Portal side before removing a custom widget in use: https://community.esri.com/t5/arcgis-experience-builder-questions/deleting-a-custom-experience-build...
Locking the entire app because of a non-existing/working widget is a pitty. My suggestion is to try to implement the appropriate workflows to prevent these situations.
In this case, it would be a simple warning message before allowing the 'custom widget' component removal if it is used in any app. For instance:
>> If there is any dependency or linked item, show up the related items and ask for double-confirmation.