You’re likely facing the dreaded SATA cable breakdown! Your Hard Drive Cable Is A Ticking Time Bomb
I often encounter this symptom with people bringing in there Unibody MacBookPro’s. I always replace the cable and as the BeetsTech article recommends I add a strip of electricians tape on the uppercase to help protect the cable.
One thing that’s also important is not creasing the cable! The sharp bends damage the thin foil wires inside. Instead I use an old BIC pen ink straw using it as a forming brake to help curl the cable where it needs to bend around. You don’t want the cable to exceed the radius of the straw.
MacBook Pro 13" Unibody (Mid 2012) Hard Drive Cable and heres the guide MacBook Pro 13" Unibody Mid 2012 Hard Drive Cable Replacement
One last think here is you should backup your drive and then reformat it as often when the drive is in this state it has errors that need to be addressed otherwise your data may become damaged.