There have been tensions between the FIDE organization and top players like Carlsen since the latter have been promoting an alternative chess organization around Freestyle chess (aka Chesss960), which has slightly different rules.
I.e. this is less about "dress code enforcement" and it is more about "Carlsen is fed up with the FIDE organization in general".
He wasn't trying to protest the dress code or make a scene, it wasn't on his mind at all. He had been out for an appearance with a sponsor during a break, then came back to the venue for the next round, and didn't notice that he was wearing jeans and it didn't cross his mind that that would be a violation.
Then he was told to change, and there wasn't enough time for him to go do that before the upcoming round. He thought he was told he could do it either after that round or for the next day, but then was told he would be excluded from that round, and at that point he said f--- it and withdrew entirely.
The controversy was about exactly how the penalty is imposed. The rule is a fine for the first violation and disqualification for multiple. It wasn't clear if his appearance for the day would count as one violation (so he could just incur the fine and wear correct clothing tomorrow), or if each round would be a separate violation. It also wasn't clear if he could play while in violation or would be excluded from each round until he changed. Precedent from other events wasn't clear for either of these.
The headline of "disqualified" is wrong and did not happen - he chose to withdraw.
I'm not saying I agree with the rule or the specific way it was applied... But Magnus definitely knows the rules.
Edit: for people downvoting... Can you please explain how the world's best chess player of all times wouldn't be familiar with FIDE rules? How is that even plausible? All of the players who compete at these events know the rules.
It makes me wonder if he's been enabled by tournament organizers being lax about enforcement of the rules for top players, when it should be the opposite - those with the most experience should be held to the highest standards because they should know better.
Women athletes who are forced to wear what amounts to underwear when the men aren't - they have a valid complaint about uniform standards. This sounds like a bunch of whiny silver-spooned brats.
For what it's worth that was the same organization - FIDE - that has made those terrible choices in the past as well.