In most countries, yes, but the trigger is residence status rather than nationality. Public health systems typically open to foreigners once you hold a residence permit and either work and pay social contributions, study, or otherwise legally reside; some enroll you automatically with employment, while others require registration and a qualifying period before full benefits. Tourists and short-stay visitors are almost universally excluded from public schemes and are expected to carry travel insurance.
Private local insurance is usually more accessible: many insurers will sell to anyone with a local address and sometimes a residence permit, though age limits, medical underwriting, and exclusions for pre-existing conditions apply. A number of countries actually require proof of health insurance, public or private, as a condition of granting or renewing the residence permit itself, so the insurance question and the immigration question are often the same conversation.