These error messages can come up in a variety of situations, but unless you have purchased your cartridges from a disreputable source the chances of them actually being counterfeit are low.
Like any printer manufacturer, HP would very much prefer you to buy a shiny new branded cartridge than to use a remanufactured version that they don't make any profit on, so they engineered their detection system to flag as potentially counterfeit everything except new unused OEM cartridges. This includes original cartridges that the user has refilled, professionally remanufactured cartridges, third party compatible cartridges... and HP's own OEM cartridges if they've printed more pages than the rated number (even if they still have ink left).
What is a counterfeit cartridge?
Basically, it's a fake pretending to be an HP original item. Ink cartridges are expensive, so inevitably there are people trying to pass off cheap low quality items as genuine OEM products. This is illegal anywhere in the world, and HP are absolutely within their right to protect themselves from such criminal activity.
However, remanufactured cartridges are not counterfeit - they make no claim to be new, original items, and are not branded as HP's products.
If you get the error message after inserting a cartridge that was sold to you as an HP original product, you should be concerned (visit HP's website for further advice), otherwise you can disregard the message.
How do I make the error message go away?
If you are using remanufactured, refilled or third party cartridges, you can clear the message with a single click, however it is important that you click the correct button as agreeing with HP's "diagnosis" will permanently disable the cartridge for use in that printer.
A typical error message looks like this:
If you are using a remanufactured cartridge (you do not believe it contains new, original HP ink) then the correct answer is "No". Clicking "Yes", which is easy to do if you don't read the message carefully, will disable the cartridge.
The exact error message format depends on your printer model. Here's another example:
In this case, the correct answer is "No" (the cartridge was not sold to you as a new, genuine HP-branded cartridge). Again, clicking "Yes" to agree that the cartridge is counterfeit will permanently disable it.
Finally, there is one more version:
This one just needs you to click "OK" (some variants of this format have a third button inviting you to buy direct from HP).
Will using non-HP cartridges affect my warranty?
No, you may see some scary-looking messages, but your hardware warranty legally can't be affected by your choice of consumables.
In the image above, there are three warnings, two of them saying that HP don't guarantee cartridges that they didn't sell (obviously) and another saying that you're not covered for repairs or service due to use of non-HP cartridges (it would be up to them to show that the cartridges caused the problem, in which case you would have recourse to the cartridge seller).
See here for more details.