Yes, as long as you have HDHP coverage. You do not need earned income; contributions can come from savings or any other source.
This is different from an IRA, which generally requires earned income. For an HSA, eligibility depends on your health coverage.
That can make an HSA useful during a job gap or early retirement, as long as you are covered by an HSA-qualified plan and meet the other eligibility rules.