They provide repair services for products 5 years after they stop selling them, which will by law be extended to 7 years for products after 2020. They clearly have the parts. See https://support.apple.com/en-au/HT201624
They have such a large volume of sales that they would be able to very accurately estimate the number of parts they need in order to fulfill their warranty obligations and paid repairs. Their inventory of old parts would presumably be earmarked for that purpose, without significant leftovers.