Here is an idea.
First, I warn you I am a 'discovery' writer, and it sounds to me like you should be too, but your write yourself into corners.
A discovery writer (like Stephen King) begins with characters and some initial situation (for him often a catastrophic supernatural situation; in The Dome, a whole town and some surrounding area is covered by an impenetrable clear dome, it cannot be tunneled under or broken through, and they must figure out what happens next. A bunch of characters are there, a promiscuous high school girl and her stalker, a thoroughly corrupt mayor, a hit man passing through, etc.
Then the discovery writer picks some scenes; confrontations and problems to deal with, and starts writing, with a focus on how the actions change the characters, and then eventually, as King himself says, the story has to come out somewhere. He says his formula is the same every time: Develop a likable and realistic character (hero), then put her (or him) "in the cooker."
So there isn't plotting, exactly. Just that the hero cannot battle forever, he learns things, there is escalation until they win or lose.
So perhaps when you change your idea, you are not escalating, or letting the character learn enough to overcome the villain.
My suggestion would be what I do: Before you begin your story, have some kind of rough idea of what you think is one possible ending. Write a page, a few hundred words, on how this winds up. Maybe not exactly how a prisoner escapes, but that she DOES escape. Maybe not exactly how the villain is killed, but something about how the hero gained the upper hand and killed him.
Not too much detail, just a sketch or guide to the ending that is NOT novel-style writing, it is a note on what to write, and definitely not so much work that you cannot discard it.
Now, when you get a new idea as the story develops, you need to do some work before you start writing it. Does your original ending still work? If it doesn't, think about your new idea, and what you have already written, and come up with a NEW sketch for your ending. BEFORE you start writing on the new idea. Again, just one page of notes on the end game and how it will work.
Do that every time you take off in a new direction, and you won't write yourself into a corner, you will always have an idea of how to end the story.
If you cannot come up with a plausible ending, do not start on the new idea! It is a dead end, or more literally, a dead ending. Always work with a live ending, your writing on the fly will automatically guide you to it.
When you are done with your first draft and HAVE an ending, then you can go back to the beginning and rewrite anything inconsistent with this ending, or move information reveals around, and make it appear as if you knew the whole story all along.