This is referred to as an HSA Mistaken Distribution.
An HSA mistaken distribution occurs when you take a distribution and later find out that it is not for a qualified medical expense. For example, this could occur if you accidentally pay for a restaurant dinner with your HSA debit card. It can also occur if you take a distribution to pay for a medical expense, but then are later reimbursed by insurance.
This is discussed in the instructions for IRS forms 1099-SA and 5498-SAinstructions for IRS forms 1099-SA and 5498-SA. (Note: these forms are submitted by the HSA bank, not the consumer, so the instructions are addressed to them.)
HSA mistaken distributions. If amounts were distributed during the year from an HSA because of a mistake of fact due to reasonable cause, the account beneficiary may repay the mistaken distribution no later than April 15 following the first year the account beneficiary knew or should have known the distribution was a mistake. For example, the account beneficiary reasonably, but mistakenly, believed that an expense was a qualified medical expense and was reimbursed for that expense from the HSA. The account beneficiary then repays the mistaken distribution to the HSA.
You have until April 15 in the year following the refund to repay the HSA and avoid the extra tax and penalty that should be paid if you were to keep the distribution that was not ultimately used for medical expenses. When you send the money to the HSA bank, you need to explicitly tell them that it is a mistaken distribution repayment, so that they can report it to the IRS correctly and it will not affect your contribution limits.