At this time (Oct 2024) this is still an open legal question with AI.
The problem is that AI learns from example writing, and it has been found that sometimes, AI will inadvertently quote some of its learning sources verbatim, and that quote is copyrighted.
Which would mean you cannot use it. Even the AI cannot use it! And AI companies are currently being sued by the copyright holders for presenting their work as their own "original work".
I agree with them, and the idea that this was inadvertent and they (the AI coders) did not expect it to happen is not an excuse; their AI is making money from copyrighted works.
They did not expect it to happen because they train on literally millions of works; and statistically it should not happen, but a hallmark of AI is we can know exactly how the individual parts work, without understanding how the millions of parts working together actually work.
And it turns out, sometimes because it was trained on this copyrighted passage, that passage turns out to be the most likely thing to spit out, verbatim, in response to a prompt.
Anyway, the law moves slow, and it is going to be a long time before this gets sorted out.
As to whether rewriting the story would work, probably yes, as long as you don't use any passages generated by the AI verbatim (because you think they sound so good).
But plots cannot be copyrighted. Character names can be trademarked (I think all the Harry Potter character names and places (like Hogwarts) are trademarked).
So sure, you can use AI to spark your imagination.
Personally, I have found AI to be very useful in doing research into things like religions or folk medicine or medieval life, that I want to portray, without using any of the AI response directly.
For example, once (for a story) it took me a whole day to research how linen was made from the flax plant. Now you can do that in five minutes, and get videos of the steps in the bargain.
To me that is a useful application for AI. And of course the AIs available for spelling, punctuation and grammar.
AI story plots, on the other hand, are going to be derivative by definition, and likely bland as well because they are the average of plots.
AI is not creative, it is strictly derivative of what it was trained on.
But good luck. Always be aware that the AI may include copyrighted passages in its material, especially if you think it sounds wonderful. It may very well be wonderful, and belong to somebody that can sue you -- whether you knew it was copyrighted or not.