For Magento 2 store owners, it is important to design the front end of the store keeping the product stock in mind. The products having more quantity must be featured or displayed in the first fold rather than out-of-stock products. For that, one has to custom code to sort Magento 2 category products by stock quantity.
If a customer orders an out-of-stock product, his order processing takes time and hence it may deteriorate the customer experience and creates a first bad impression.
For more info: https://meetanshi.com/blog/sort-magento-2-category-products-by-stock-quantity/