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.
Magnus pants were fine. He is absolutely correct that they were singling him out and you can look back to many recent tournaments to see the clear double standard.
FIDE is an agency that exists to promote and develop chess.
Magnus Carlsen is the biggest draw in the chess world by far.
A minor dress code violation should have been dealt with a fine as the rules very much allow for the benefit of the game.
Also, I don’t think there’s a single player who would complain about that (well, other than Kramnik, but Kramnik complains that spectators breathe too loud and that’s cheating).
And then FIDE should have stepped back and thought about the recent growth in the popularity of chess, since the pandemic and thanks to the work of the likes of Magnus and Gothamchess and should have reconsidered the strict dress code rules in the first place.