I am afraid I have essentially bad news for your client. German law is quite liberal in recognizing marriages concluded abroad, but adamant about marriages within Germany. If they are not concluded before the registrar, they are not valid under German law.
However, the marriage may be considered valid under German law if all of the following requirements are met:
1) Neither spouse is a German national - I think that is the case.
2) The ceremony conducted by the imam would in itself suffice for a valid marriage under Afghan law at the time - that I do not know.
3) The Afghan government (represented in particular through its embassy or consulate in Germany) had authorized the imam in question to conduct marriages on German soil by a verbal note to the German government; it is widely believed that such a verbal note need not name the imam in
question personally, though.
In this case, the religious marriage could have been registered as such in Germany, and registration would be considered (rebuttable) proof of the validity. However - and this may be important to you - this is the only case where registration does not have constitutive, but declaratory effect - i.e., there could be a valid marriage under German conflicts law on German soil without registration in Germany.