I'm an Iranian citizen and my boyfriend is German. We're in love and have known each other for 2 years. He travels to Iran to visit me and my family. We're going to marry in Germany, but I have a tourist visa. Can we still get married there? It's a genuine marriage and not for resident permit purpose.
As far as I know, as long as you are in Germany legally, you can marry your partner (personally, my partner was not even asked for her visa).
If you thought getting a visa might have been a lot of paperwork, let me quote myself from another question:
However, German authorities require a lot (and by a lot I mean a lot) of paperwork you will not get in a month. You both need to be physically present to swear that all your data is correct, then you get an appointment to marry and then you marry. You need all the paperwork to be in order to even get to the swearing/appointment getting part. Oh, did I mention that all your paperwork has to be translated to German by a certified German translator? And it needs apostilles from your respective home countries. Oh, they need to be translated as well. By a certified translator. English may be an official EU language, but that does not keep German authorities from refusing to accept it. Oh, and all of it has to be recent, nothing older than 6 months.
I went through all this with one party being German national and one party being a non-EU foreigner. It took us half a year to get the paperwork and translations.
The costs of the translations alone would have been enough for a two-person trip to Vegas including getting married by Elvis. And they don't want to see any of the paperwork either except for your ID.
So yes, you can. But please make a solid plan and get all the documents and approvals or you are in for a big disappointment. It will take at least two trips or a very solid planning. Don't expect to be able to "just marry" here and be in contact with the local Standesamt all the time to double and triple check it. Germans are... uhm... fixated on their paperwork. Even a tiny little piece missing will make you go back unmarried and in for another trip. When I mentioned Vegas, that was no joke. It's sooooo much easier in other countries.