NHS has a page where you can check whether you are eligible for free treatments or not. Note, that GPs are free, but they don't have to accept new patients. Also going to an A&E, Walk-in centre or a Minor injuries unit is also free unless they need to admit you to a hospital. In the hospital some treatments are still free, for example infection treatments, including STDs.

Hospital treatments are a bit more complex.

To get free healthcare at the hospital you either need to be in one of the exception categories (like living in a country which has a bilateral healthcare agreement, being an EEU citizen, etc.), or be an ordinary resident in the country.

The latter part can be hard to prove, as there are no strict guidelines on who counts as ordinary resident, and who not. According to HMRC you have to be:

In the country legally

With an intent of actually staying in the country

Note, that the latter part does not talk about having to work or studying in the UK (actually being employed or being enrolled in an educational institution does not mean you are an ordinary resident).

Also to determine whether you can be considered an ordinary resident or not the government issued some guidance about it. Basically it's up to the local authorities to decide whether you are ordinary resident or not (in their area), in this case it's up to the hospital to decide. If they don't think you can get free healthcare then you have to prove that you are an ordinary resident by showing

evidence that you're looking for work

evidence that you have bought property in the UK or have rented a property

papers that show you've applied for benefits

evidence that your children are attending school in the UK

The hospital might also ask you for evidence to prove that you're legally entitled to live in the UK, such as:

your British passport, or

permission from the Home Office

If you don't yet have permission from the Home Office to stay permanently then you'll be charged for hospital treatment until: