Well, I think a big reason for those (at least more so in tv shows, manga, anime etc.) is that writers cant be sure if the show will continue, there is no guarantee if it going to get new seasons, more books etc. Why would you waste time thinking that far ahead if there is a risk that a show wont get enough views and will be closed just after 1st season or just after few episodes? A lot of mangakas often have only rough idea how their manga will go or what ending it will have when they start just because of that. If manga becomes popular they can be forced to milk it for a very long time or they can just do it because maybe they dont believe they will ever create something that popular after that it ends. Its just a job security. Does it excuse bad writing? No, I dont think so, but it is what it is.
In movies, well, its all about money. I mean, Joker movie doesnt need a sequel, but its almost guarantee that a lot of people gonna see it, right? Star Wars wasnt made with a sequel in mind too. Well, right now in hollywood they think more about how can they push an agenda rather than a good writing. I dont think they care if ending is good or bad.