Praise be to Allah.
There is no saheeh hadeeth to suggest that it is mustahabb (encouraged) to do the marriage contract in the mosque; rather there is no evidence for believing that it is mustahabb to do it in the mosque. Shaykh Ibn ‘Uthaymeen (may Allah have mercy on him) said:
I do not know of any basis or evidence from the Prophet (blessings and peace of Allah be upon him) to suggest that it is mustahabb to do the marriage contract in the mosque. But if it so happens that the husband and the guardian of the woman are present in the mosque and they do the marriage contract, there is nothing wrong with that. But as for that being mustahabb in the sense that we would tell them to leave the house and go to the mosque, or make an appointment to meet in the mosque and do the marriage contract there, this is something for which evidence is required, and I do not know of any evidence to that effect.
End quote. Liqa’ al-Baab al-Maftooh, 167/17
Rather some of the fuqaha’ regarded it as mustahabb to do the marriage contract in the mosque for the sake of the barakah (blessing) of the place, and so that the news of the marriage would become widely known, and some of them also based this on the da‘eef hadeeth that speaks of that.
See: al-Mawsoo‘ah al-Fiqhiyyah, 37/214, 41/221
See also the answer to question no. 132420
Similarly, many people nowadays think that it is mustahabb, because if the marriage contract is done in the mosque, this will prevent many of the actions that are contrary to Islamic teachings, but usually happen if the marriage contract is done somewhere other than in the mosque, such as haraam mixing of the sexes, smoking, listening to music and other things that are prohibited.
With regard to the question of where the Prophet (blessings and peace of Allah be upon him) did the marriage contract for his daughters, this is something for which we do not know of any evidence in the reports. It does not seem that the location of that was something that people at that time attached any importance to, which would make them want to find out about it and transmit it to us. Rather that happened – as would appear to be the case – in their ordinary gatherings or in their houses or wherever they happened to be, and we have not found any report that speaks specifically about that.
And Allah knows best.