my truck had a problem with this untill i replaced the Speed sensor, and instrument panel. and even now i still have speedometer issues, but the shifting is fine for me now.
I agree that checking the fluid level and condition of the transmission fluid is an excellent place to start. You might also check the drive line for issues such as a loose U joint or perhaps some slack in the rear differential but what you describe sounds a lot like a transmission problem and if it can’t be cured by correcting the fluid level then perhaps there is an internal issue causing the problem.