Assuming the chain is not worn out, my guess is the RD hanger is bent.
Was the bike shifting ok before being put on the trainer, but still with the trainer skewer?
Most trainers use internal cam skewers, which pull tighter than non-internal cam ones. They probably adjusted as best they could with the bent hanger, but never fixed it. The trainer skewer applied additional pressure exacerbating the issue of the bent derailleur hanger.
Your LBS should have a tool for checking if the hanger is bent, and most likely, they can bend it back. Or you can buy a new one.