Deductions & credits

In the original question, the period of non-use occurred both AFTER they used it as their main home, but also BEFORE they used it as their main home (because they moved back).

Timeline
Main home ---->rental---->sale   does not trigger the non-use rule.

Main home --->rental--->main home--->sale  does trigger the non-use rule.

You have to go back to around 2010 to find a version of IRS pub 523 that does a good job explaining this.  Most recent versions omit the details and refer the taxpayer to a tax preparer for extra help.