I've the k-r, and for other reason I've opened it up to the mirror mechanism, and I can say what the problem could be... I found the last gear (gear n°7 from motor, the one with sliding contacts on it) with 2 problems:
one)) the grease with time and use moved from the center shaft all around on the contact flex board, causing bad contact and help making resistence, so the camera loose signal and maybe can turn around and around............
two)) the gear has two cams under it, that needs to flip up the mirror and to charge the shutter, the first cam was consumed by use, because not thick enough (it's plastic) to push that spring 1000000000 times
I don't know if the K5 it's the same, I think this can really be one of the "mirror flop" reasons.
The reason about disassemble my entire k-r is here:
https://www.pentaxforums.com/forums/general-technical-troubleshooting/195494-...y-problem.html