I guess I'm surprised - because like you - I figure they basically treat everyone regardless. I know that has been one of the big debates about charging, is that it isn't the NHS's responsibility to "police" who is allowed and not allowed to use the NHS without cost at the point of service.
NHS staff will report to UKVI if they find someone trying to defraud their Trust. What made you think they didn't? Sometimes the person using that NHS number won't match the medical history of the person who really has that number and the NHS staff are the ones that spot that.
NHS staff can also phone UKVI if they are not sure about that persons status. UVKI use a banner system on the NHS SPINE system, red banner to bill and green banner not to bill. The NHS Trusts also report details to UKVI of a patient with any total debt of £500+ if it is not paid within 2 months, etc.
Government departments will share infomation they hold and carry out sweeps for each other. Sharing information they hold on people with UKVI, is no different to sharing with any other government department.