Changed a mates cassette on Friday. He’d also been having shifting problems the same as you are describing OP.
Turns out that the mech was bent, the spring in the cage was over stretched and floppy, and the mech hanger looked to be slightly out. I borrowed a Park DAG1 from my LBS. The hanger turned out to be properly bent. Put a new one in but that was still out. Ended up with the wheel out, a g-clamp on the hanger bolt so I didn’t strip the threads, and an BIG Bahco adjustable spanner on the frame to get it somewhere near straight. Minor adjustment with the DAG, a new rear mech, and it all shifts sweetly now.
So yes, probably a bent hanger. Only needs to be a bit out for it to have an effect.