Did you pull the whole gear out of the transfer case to make sure it is actually there or just check that the wiring was connected?
The gear should be removable:
also check the writeup of speedo gear changing:
But since you suspect an electrical problem rather than mechanical, unplug the speed sensor at both ends, clean the metal contacts with alcohol and then put some electric contact grease on there (the little 30 cent packets from autozone). This can fix a lot of electrical problems in old cars.
Next, you should suspect that a mouse ate through the wiring. Use a multi-meter to check the following:
(Someone else correct me if I'm wrong!)
From the speedometer wire connector on the transfer case:
Wht/Org should have continuity from the transfer case to the Wht/Org on the speedometer wire under the dash
Org should show a voltage when measured to ground when they key is in the on position
Blk should have continuity to ground
Under the dashboard on the speedometer sensor:
Wht/Org should have continuity with Wht/Org on the transfer case connector (as described above)
Dark Blu/Wht should show a voltage when the key is in the on position
Blk should have continuity with ground