The cause of something like this could range from
a defective vehicle speed sensor (in the transmission) to failing friction material in the transmission clutch packs to hydraulic control faults in the transmission valve body and / or the transmission shift solenoids...