The intended purpose of a HSA is to allow you to pay for medical expenses tax-free. Additionally, a HSA allows you to invest money in stocks or other funds similar to how you would invest money in a 401k or individual retirement account (IRA). That money is then available to use for qualified medical expenses.
Using a HSA to fund retirement is a personal decision. While this is not financial advice, if you wanted to consider doing the same here are the steps you’d want to follow.
Pay medical expenses out of pocket and invest your HSA funds. This is the key if you want long-term compound growth in your HSA. My HSA is currently invested in a low-fee S&P 500 index fund. Make sure you take the time to invest your HSA money or else it will sit in a regular account and not accrue any interest.