I had this same problem sometime ago in 2018. Both the speedometer and the odometer were not working. The cause of the problem was that the 12mm bolt used to fasten the speed sensor was broken so there was not enough contact.
After the broken bolt was removed and replaced, everything started working perfectly to this day.
Check if the sensors are correctly fastened. If they are, have them removed and cleaned. Replace them. If the problem persist, it means the sensors are bad and need to be replaced.