What happens when a PhD student finishes the thesis but is forced to defend way after the contract ends?
It is fairly common (at least in Germany) that the date of final defense is after the contract/funding ends. What should happen in this case is that this is discussed between the PhD student and the advisor as soon as possible. And with "that" I mean the funding/employment situation. Actually, there should be a discussion about the future plans of the PhD student somewhere around the last half year of write-up and if the advisor does not initiate this, the student should do it. Indeed, PhD students can have different plans, e.g. "having a job outside academia secured an wanting to start as soon as possible", "wanting to apply for postdoc positions", "continuing at the current place in some way", "applying for a fellowship somewhere"… In each of these cases advisor and student should proceed differently and without knowing the situation, things may go the wrong way.


  Is this treatment considered fair for A (given that other PhD students in the same office stay 5 or 6 years without anyone being bothered)?


I can't judge "fairness" but for sure it is unfortunate. But if nothing regarding the defense date and the further plans of the student has been discussed, delays in the defense date are common (and in some cases no problem for anybody).


  Is there anything A could do to avoid being in this situation? Or A should just accept that "that's how things are" and move forward?


See above: Discuss exactly this matter as early as possible.


  How can A then ask for a recommendation letter with such treatment?


I do not see how recommendations letters are influenced. 


  And finally: What does this say to the external committee? Is it possible that this would create a very bad image for A to the reviewers? 


Since procedures for the review of PhD theses are quite different at different places, I don't think that the process has any influence of the external reviewers.