A product page that's earned rankings and links shouldn't simply disappear the moment it goes out of stock.
Keep the Page Live When Possible
If the product will return, keep the page indexed with clear messaging rather than removing it and losing accumulated signal.
Redirect Permanently Discontinued Products
For products that are genuinely gone for good, a redirect to the closest current equivalent preserves value for visitors and search engines.
Offer a Real Alternative on the Page
Suggesting a similar in-stock product on an out-of-stock page keeps visitors engaged instead of bouncing.
Next step: Use the Google Cache Checker to see how a discontinued product page is currently indexed before you decide how to handle it.