What does the manager do when this happens? I have been there. The answer is simple, I did exactly what I would do if the exact candidate I interviewed showed up but fell short of expectations (say used google extensively, or the questions were theoretical and they were good talkers - happens with QA and Project Manager jobs). If they are borderline, give them a task, see if they are able to complete it. A Manager should do it anyway, interviews are hard. Most companies have probation periods for this reason.
Why does it happen/what’s in it for the candidate/contracting firm? For the candidate a few weeks or months of experience that they can add to their resume. Do it in 3 or 4 places and suddenly you are a mid level developer. Hopefully they also learn a bit of programming in the meantime. For the contracting firm any money is money. Sketchy IT contracting forms routinely do this and worse.