What makes this question tough to answer is HP, Dell, etc are not known for giving customers options on what cooling they can pick.
The only people who need to consider a good CPU cooling are the people who need a high-end CPU in their computer and they're using that CPU to process heavy workloads. If you're just buying the PC for normal office tasks and you're getting a PC with a Core i5 or Ryzen 5 then you shouldn't need to be overly concerned with what CPU cooler come with it. All you would need to do is open up the case and clear out the dust. The only way the cooling is going to fail is if the fan fails or the heatsink mounting mechanism fails.
The catch 22 here is you will get better cooling if you replace the CPU cooler with a decent aftermarket cooler. The downside here is this will void your warranty. The CPU cooler that's used is cheap and these cheap coolers have a hard time working with modern day multi-core processors.
One example I can give you is the stock cooler that comes with the non-K Core i7-8700 is not effective enough to keep that CPU cool during heavy workloads. This CPU really need a decent aftermarket cooler to be paired with it. On the upside a decent cooler can be purchased for right around $30usd
-Stick to a midrange CPU that doesn't consume gobs of power. Processors like the Core i5 and Ryzen 5 are easier to keep cool than a Core i7 or Ryzen 7.
-Avoid SFF and All In One's. Those small SFF cases are bad enough but the A-I-O are worse. A mid-tower or a larger tower is easier to keep cool.
-GPU? If you have a GPU in the case, the heat will rise and this will effect the CPU. If you insist on a PC that has a decent Graphics card (GPU) then look for something that has the power supply mounted on the bottom and a more effective CPU cooler. At this point the case needs an intake fan with an exhaust fan.
-Consider a different brand that has more specialized builds or have a local shop build you a custom PC. HP, Dell, Acer, and Le-no-go (Lenovo) all buy parts from whichever supplier is the cheapest. The midrange models that cost around $1000 or so are clearly better than a low end model but sometimes parts are lacking in those low end models. I've had lemons and Gems from all brands.
-The best option for higher reliability is a larger heatsink. Some of these 'gaming' computers come with an AIO cooler (Liquid cooler). These AIO coolers are effective but they only rival medium to large heatsinks. The problem with an AIO cooler is it contains liquid and it uses a Pump to circulate the liquid. AIO coolers have been out since 2010 and they rarely ever leak but pump failure is more common. The other problem with an AIO cooler is Glycol is used as the coolant. While Glycol gets along with the aluminum radiator, it tends to fail after 5-7 years.
-You an use a program to track the CPU temps but that won't solve the problem. All this will do is let you know when the problem is happening.
-What does matter is the bearing system that's used in the CPU fan. Sleeve bearing fans are junk and these will fail within a few years. Fluid Dynamic bearing and Ball bearing fans will typically last for years. On the sad side of things, many of these aftermarket CPU coolers come with sleeve bearing fans.
-If the inside of the case can accommodate another case then, then install it. Getting better airflow through the case will do wonders for preventing CPU fan failures. One time I installed a Graphics card inside a normal sized mid-tower HP. The heat from the graphics card built up around the top of the case and this made it very hard for the CPU to stay cool. I upgraded the CPU cooler which helped a lot but the best thing I did was transferred all the parts to a better aftermarket case that had better aifflow.
-If you are committed to HP and you want something with a Graphics card, then you can always look at their OMEN line. This might cost more but the CPU will come with a better cooler. At this point you would be buying HP's equivalent to Dell's Alienware line.
-The Thermal Interface Material (Thermal Compound, TIM) only lasts so long before it fails. Typically the TIM will separate and form dust-like spots. TIM is made up from oils, Ceramics, and silicon compounds. You can keep track of your CPU temps and when the temps start looking off you can replace the TIM. Typically this happens after 3-6 years. There are some aftermarket TIM's that can last a long time like Arctic Silver 5 which has Silver in the compound. Avoid any TIM's that use Diamonds since these will pit and pock your IHS and heatsink base.