from IRS publication 523:
“If you become physically or mentally unable to care for yourself,
and you use the residence as your principal residence for 12 months in the 5 years preceding the sale or exchange, any time you spent living in a care facility (such as a nursing home) counts toward your 2-year residence requirement, so long as the facility has a license from a state or other political entity to care for people with your condition.”