I’ve never heard of it being illegal to marry on a Tier 4 visa before and I recall several people here on the forum doing it and then switching to FLR(M) from their Tier 4 visa with no issues.
A couple of years ago, if you wanted to marry on anything other than a fiancé visa or a marriage visitor visa, you needed to apply for a Certificate of Approval (COA) to get permission, which took about 6 months to be processed. However, they abolished the COA about 3 years ago, which meant that people on work visas, student visas or even visitor visas could just get married in the UK anyway without any extra paperwork.
So, now, while you’re not supposed to marry in the UK on a visitor visa, there’s nothing legally stopping you from doing so if the church/registry office will allow it. As far as I’m aware, the same is true for Tier 4 student visas too.
However, I believe they are cracking down on marriages in the UK, by extending the amount of time for giving notice and I think they are aying particular attention to people on temporary visas who try to marry just before their visa expires in order to try to stay in the UK (i.e. trying to weed out sham marriages where the Tier 4 visa holder will do anything to stay, including marrying someone they barely know).
The new rules for giving notice to marry are here, but they don't come into effect until next week - they don't say that you can't marry on a limited leave or temporary visa, just that you may have to give much more notice before you can marry (up to 70 days):
https://www.gov.uk/government/uploads/system/uploads/attachment_data/file/377482/Marriage_notice.pdfUnless there’s a new rule we’re not aware of, it could be that the IO at the airport was mixing up these new rules and not fully understanding them. There’s no way that the marriage can be illegal, since a marriage certificate is a valid, legal document. The only debate here should be whether or not you should have been allowed to marry on the Tier 4 visa in the first place (which I believe you should have) – but that doesn’t invalidate the marriage.
I know that you don’t have your visitor visa refusal information yet, but what documentation did you send with your application? There are various requirements you need to meet for a visitor visa and you would have needed to provide physical, original evidence to meet them in order for the visa to be approved.