Given the trend in transistor pricing, margins need to go up in anticipation of future costs going up.
Net margin for Nvidia is reported at 42%. To be fair, they could probably run at 25% net margin like notoriously expensive device maker Apple does and be fine if they had to and still be fine...
...they just don't have to, because the consumer is willing to pay their prices. Nvidia is under no pressure to run at lower margins, so why would they? We can't complain about price creep when we pay it anyway.
That said, I don't think the gaming/consumer market has much pricing power anymore. Considering what Nvidia is selling H100s for, my guess is they do what they can to maintain their market share in gaming (which is still an $8 billion market for them, so sizeable), but you're going to pay what they tell you to pay. Don't want to pay it? No problem, they'll just throttle supply and redirect more to AI applications.
But yes, you're right. There are two factors here, because like Nvidia, TSMC is also taking advantage of their pricing power. Want 3nm? Where else are you going to go? Pay up.