If a product is temporarily out of stock, keep the page live, show when it’s expected back and suggest alternatives, so you don’t lose its rankings. If it’s permanently discontinued, redirect the page to the closest replacement product or its category so the SEO value isn’t lost.