Out of stock products always going last
The products with "out of stock" status showing in all loops (category, related products, other archive terms) randomly with other in stock products.
Now many developers using non-native code to show out of stocks products at the end of pages\archives.
I think it must be in-core realization. Out of stock products still present on the site at the end of own categories, it shouldn't appear in related products, up-sells, cross-sells and other loops.