It is illegal in Germany. The German Criminal Code (Strafgesetzbuch, StGB) says:
Section 271 Causing false records
(1) Whoever causes declarations, negotiations or facts which are of relevance for rights or legal relationships to be recorded or stored in public documents, books, data files or registers as having been made or having occurred or having been stored although they were not actually made or did not occur, or were made or occurred in another manner, or by a person lacking a professed capacity or by a different person incurs a penalty of imprisonment for a term not exceeding three years or a fine.
[...]
(4) The attempt is punishable.
Section 276 Procurement of false official identity documents
(1) Whoever
undertakes to import or export or
with the intention of using it to facilitate deception in legal commerce, procures for themselves or another, stores or gives to another
a counterfeit or falsified official identity document or an official identity document which contains a false notarial recording of the type indicated in sections 271 and 348 incurs a penalty of imprisonment for a term not exceeding two years or a fine.
A "public document" in the sense of § 271 I StGB is also a foreign document if it has some reference to Germany (Freund, in: Münchener Kommentar zum StGB, 3. Auflage 2019, § 271 Rn. 16). A "official identity document" in § 276 I is also a foreign document, e.g. a passport (Erb, in: Münchener Kommentar zum StGB, 3. Auflage 2019, § 276 Rn. 2; BGH, Beschluss vom 29.7.2000, 1 StR 238/00, NJW 2000, 3148).
So it is a crime in Germany to fraudulently obtain a foreign passport, to import or export such a passport or to store the passport with the intent to use it for forgery. As foreign identity documents are used domestically on a regular basis when dealing with foreigners, it is reasonal to punish such acts domestically.