A mariage that is only made to get citizenship or a residence permit is illegal. The german legal term for it is "Scheinehe". This is defined as
Eine [Scheinehe] liegt dann vor, wenn das heiratswillige Paar offensichtlich keine Lebensgemeinschaft führt, sondern die Bestimmungen über Zulassung und Aufenthalt von Ausländerinnen und Ausländern umgehen will.
A fakesham marriage (is there a better english termsee below for it?terminology) is on hand when the couple that requests the marriage obviously doesn't live in a partnership but wants to circumvent the laws about immigration and residence of foreigners.
The marriage registrar may deny the marriage, or it may even later be voided.
This source says that you can get a fine or a prison sentence of up to three years for this. If one even takes money to enter a fake marriage with someone, the sentence can be up to five years.
So, better wait for the right one ;-)
Terminology remark: It needs to be distinguished between the terms "Scheinehe" (english "sham marriage") and "Konvenienzehe" ("marriage of convenience"). The later is a marriage mostly to keep one's social status and is typically arranged by the parents. This is legal and was very common in former times. In some countries, e.g. in India, it is still common. It differs from the sham marriage by the fact that the social status of both spouses is the same.