The answer to this question depends on the specific visa situation of the spouse. Only for cases listed in §§ 39, 41 AufenthV a residence permit can be applied for from within Germany. Among others (likely irrelevant ones) this applies if:
1) he or she possesses a national visa (Section 6 (4) of the Residence Act) or a residence permit,
2) he or she is exempted from the requirement for a residence title and the exemption is not restricted to a certain part of the Federal territory or to a stay of no longer than six months,
3) he or she is a national of a state specified in Annex II to regulation (EC) no. 539/2001 and is lawfully resident in the Federal territory or possesses a valid Schengen visa for short stays (Section 6 (1), no. 2 of the Residence Act), provided that the conditions pertaining to an entitlement to a residence title are met after his or her entry into the Federal territory, [...]
6) he or she holds a residence title issued by another Schengen state and, by virtue of this residence title is entitled to reside in the Federal territory, [...]
If the partner holds a short-term Schengen visa or can enter Schengen visa-free one might be inclined to think that the number 3 applies. Unfortunately this is not the case if the marriage happens outside Germany. This case is explicitly spelled out in the administrative regulation for the German Residence Act (Nr. 30.0.9 VwV-AufenthG) which also is confirmed in a few court cases (with a slightly different premise, e.g. BVerwG, 11.1.2011 − 1 C 23/09):
Ein Ausländer, der mit einem Schengen-Visum ins Bundesgebiet einreist und nach einer Eheschließung im Schengengebiet (z. B. Dänemark) ins Bundesgebiet zurückreist, reist i. S. d. § 39 Nummer 3 AufenthV ein. Der Einreisebegriff des § 39 Nummer 3 AufenthV ist nicht schengenrechtlich zu verstehen, da es hier um eine Zuständigkeitsfestlegung (auch) für den Bereich nationaler Visa geht. In diesem Bereich gibt es – vorbehaltlich spezifischer Harmonisierungen – kein Gebot gemeinschaftsrechtsfreundlicher Auslegung.
Which translated and without the legalese basically means that if one marries outside Germany § 39 Nr. 3 AufenthV doesn't apply as the conditions for an entitlement to a residence title were not met within Germany.
Note that those two references only explicitly talk about cases were visa are required. However the same also applies for non-visa nationals as Nr. 3 requires a lawful residence for those. If one enters Schengen with the intention of staying longer than the allowed visa-free period then the entry was not lawful in the first place (see e.g. VGH Baden-Württemberg 14.9.2011 –11 S 2438/11). If one would enter Schengen without the intention of marriage and then decides to marry outside Germany I don't know the answer and don't think such a case was ever decided on a high level but I think that should be possible.
The only exception would be if leaving Germany to apply is deemed unreasonable (within the meaning of § 5 Abs. 2 S. 2 AufenthG). This is normally the case if the applicant (Nr. 5.2.3 VwV-AufenthG):
- is caring for people in the household which can't be ensured otherwise
- can't travel safely to their home country or there is no German embassy
- is pregnant, sick, disabled, or of high age
High cost alone is not a reason.