I had gradually warmed to self publishing over the years, but I didn't think it was for me. I'm writing mainstream fiction, and my goal is trade publishing. Then I got the idea for a series and was told that if I trade published it, and the publisher decided to end the contract, I wouldn't be able to sell additional books in the series elsewhere or to self publish them. If that's true, then I won't even consider trade publishing my series; I'll self publish under a pen name. I still think mainstream publishing is the best choice for my mainstream work.
It's not true.
Unless you sign some sort of dreadful contract that no respectable agent would advise you to, then you retain all the rights to any future books and can do with them as you wish.
A publisher licenses the right to publish a book from you. As part of that contract you will agree to not publish books that will compete with that book for the duration of the contract.
When a publisher decides to terminate their license to publish your books, the rights return to you and the contract is not in force (other than the warranties and indemnities clauses.)
You're free to publish anything you want. Sequels, prequels, further books in the series. Whatever your creative heart desires.
That's the legal side of things.
The reality is that it's very hard to move a series from one publisher to another. I've seen it done, and I've done it, but it's not the norm. It's not that the contract doesn't allow for it, it's that if a series isn't doing well enough for the publisher to continue, a second publisher rarely thinks "oh, I can do better! Here let me!"
On the other hand, you can self-publish the continuation of a series no problem. I've seen a LOT of authors do that quite well.