Sometimes a writer will know they want a beloved character to sacrifice themselves at the end of the second act, but they'll leave the details for later.
Certain groups, whose names we shall not mention, have made careers out of pointing out the ridiculous stuff pulled by Hollywood screenwriters who don't want to put in the time or effort to produce a credible scene.