Your solar system should last well over 25 years.
The general rule of thumb in the solar industry is if your roof is 25-30 years old, you should look at replacing your roof prior to installing a system. At the very least, have it inspected beforehand.
If you put solar on a roof that needs to be replaced after a couple years, it's not a big deal. You'll just need to work with a roofer who is comfortable taking the panels off and then putting them back on. Most roofers are capable of this these days.