It sounds to me like a connection problem. Maybe some loose wiring? Driving probably jumbles the wires so they connect again. maybe try check the connection wires, some electrical tape maybe your answer.
Have you checked the speedo cable. make sure it's plugged in securely at the speedo place a drill on the trans end and spin the cable and see if the speedo works.If thats ok check the driven gear at the trans,where the speedo cable connects.