What you are seeing is Adobe’s patented Paragraph Composer at work.
Other than most word processors (Microsoft Word, I’m looking at you), the Paragraph Composer checks the line length of every line agains every other line, and makes them as equal as (mathematically) possible. Thus, if moving a word to a next line decreases that line’s length, it is because the alternative is worse. Sure, when unaltered that paragraph may have one full line more but you can be sure somewhere else another line will be way shorter than everything else, and thus will be less perfectly filled.
The algorithm is designed to work best with fully hyphenated and justified text – in which case it will minimize different space widths between consecutive lines – but the same thing also works for ragged, unhyphenated text.
That said: the Paragraph Composer is only the default setting, but of course you can change your text to use the Single Line Composer. That name does not mean it only works on single lines, it’s just that it only considers one line at a time. It uses a straightforward rule to break paragraphs into lines: fill with words. Last word does not fit? Break there.
While it may sound as if filling one line at a time should yield “the best” line breaking, that is not the case. Inside any moderately long paragraph, you might spot occasions where it would be nicer to move the final word of a long line to the start of the next one, so you don’t get one very full line followed by one that is visibly much shorter. The Paragraph Composer does check for that, in the extreme: it minimizes all deviations in the entire paragraph – just because moving one word at the first line may influence the very last line to make the entire paragraph more even.
Here is David’s view on the Paragraph Composer: https://indesignsecrets.com/the-importance-of-paragraph-composition.php (we pretty much agree on this).
Instructions to change the default composer (for some of your paragraphs only, or, if you have consistently been using paragraph styles, for all of your document) can be found in Adobe’s Online Help: https://helpx.adobe.com/indesign/using/text-composition.html