probably a mostly hardware issue
The scroll wheel is an optical device. There are holes in the wheel just under the surface. The holes are very thin slots oriented almost like spokes. Then there are two pairs of infrared diodes and photo receivers. These are precision offset so that only one IR diode is shining through the slot at any given time. With this setup the direction of rotation can be determined based upon which slot goes high to low relative to the other. It can be difficult to wrap your head around how this works at first, but most rotary encoders, like sound knobs that can spin infinitely, work on this principal. If stuff like lint and dust blocks these slots or the light from the diodes gets around the wheel somehow it creates problems. The microcontroller needs sharp digital edges for this to work well.
Other than dirt and grime, mechanical buttons fail. Corrosion is common from skin moisture and stuff.
The actual chips used are extremely integrated for the camera used for the mouse movement, buttons, and scroll wheel.
In all consumer garbage, the cheap electrolytic capacitors are suspect. If one of these fail, it will cause intermittent problems. These capacitors are like mini reserves or energy buckets. When there is a big sharp current draw that causes the voltage to dip, the caps are there to smooth out that dip and provide a small reserve capacity near the likely source. Electrolytic caps have a fluid inside that, when dried out makes them stop working and act more like a resistor in most cases. When a cap has high equivalent series resistance, the respective voltage rail may go low and cause very unpredictable behaviors. Only some parts of the circuit may start to fail at these brownout voltages and then immediately resume or any number of other behaviors.
Likewise, a lithium battery may start to have issues with providing enough current and fail in a similar way causing brownout issues.
The big current draw in this instance will be the radio. All radio transmitters, even in little wireless devices like a mouse, use a ton of power in extremely short bursts. This is hard on circuit components. The efficiency is due to sending very short pulses less often, but the power required is always high.
It is likely that, if it has a lithium battery, this has gone bad from charge cycling. Charging a lithium battery requires at least two of three charging phases. If a cell is dead, a very slow trickle charge is required. The two standard phases are a constant voltage and then a constant current phase to safely charge lithium batteries. These phases require some simple feedback. If the cell is charged in the constant voltage phase, but it fails to reach the required voltage for the constant current phase, this may prevent a simple charge controller from completing the charge cycle. Most consumer junk with a lithium battery is going to have a very simple batman charge controller setup. It is likely/that the batman is not connected to any logic or digital feedback mechanism that evil HP controls. They are principally cheap bastards so overly optimizing profit over functionality is likely, like Boeing flying the doors off level corporate suite stupidity.
Along those lines, if not lithium, circuit noise would also be suspect, likely from degradation from grime and corrosion. There are often two PCBs in a mouse with some kind of connector between them. This often will be your failure point from moisture as the galvanic potential is high between the different metals in contact and mechanical stresses.
limp wrist, lighting, and black bg