I will assume, and it seems you do understand, that once you are eligible for Medicare (any part) and sign up for Medicare (any part), you cannot contribute to the HSA any longer. That also means that you cannot sign up for Social Security either since you have to be signed up for Medicare Part A, at least, for your retirement benefit.
Now how can you use it -
Two HSA withdrawal rules apply differently to those aged 65 or older (irrespective of Medicare
enrollment)than to most individuals under the age of 65.
- First, although health insurance premiums generally are not considered an HSA-qualified medical expense, this restriction does not apply to individuals aged 65 years and
older; these individuals may treat any health insurance premiums (including Medicare Parts A, B, and D and Medicare Advantage premiums) as qualified medical expenses, EXCEPT for premiums for Medicare supplemental (Medi-gap) policies. - Second, although withdrawals not used to pay for qualified medical expenses must be included in an individual’s gross income and generally are subject to a 20% penalty tax, the penalty tax does not apply if made after an individual reaches the age of 65.
Congressional Reserarch Service.gov 02/11/2020 - Health Savings Accounts (HSAs) and Medicare
The reason that Medigap (Medicare Supplemental) premiums aren't included in this rule is simple - Medigap coverage is really NOT health insurance premiums - it is gap insurance.
It's Always Something . . . . Roseanna Roseannadanna