The studio knows that a sequel will have a guaranteed $ minimum return just because it is a sequel. Hence they can estimate how much to sink into production to guarantee a profit. Then they green light the movie production for that budget.
Same goes for the cast. The studio finance dept can look at previous years data and predict that $ million will be guaranteed to be made just because the movie stars Jennifer Aniston or Adam Sandler. Irrespective of the what the movie is about. Just because people see the name and wander into the theatre while on a date or buy the DVD for $15.99 at the grocery store. This provides a target production budget for green lighting the movie. Then they hire a director and try to figure what the story will be about.
The China market also affects cast and story. See https://www.youtube.com/watch?v=8R-FQTY4KJk