A sub-task should always have a parent issue, and it's not possible to change the parent issue of a sub-task.
I can only give you two possible alternative solutions:
Instead of removing the sub-task, we can automatically close the sub-task (i.e., move to status "Closed", "Done", or similar) when parent issue is closed.
Instead of using parent - sub-task relation, we can use a custom issue link type (e.g., "is parent of / is child of"). We can freely break and create issue links between issues, so we can break the issue link between parent and child issues.
Let me know whether any of these solution is OK for you, and I can give you the details to implement it.