The speedometer gear housing must be rotated properly so the speedo gear properly engages its pinion gear. It's possibly nothing more than that. There are certain positions the housing must be at depending on the speedometer gear tooth count so count the teeth and rotate the housing so it is lined up properly. You'll find the tooth count ranges on the housing so just line up the housing to match what is indicated. Even when pointed at the right index mark, you may still have to rotate it a bit more to get the gear to engage properly.
And when the speedometer doesn't work from this problem, a Check Engine light will result.
And when the speedometer doesn't work from this problem, a Check Engine light will result.