if the UK gets an advantageous deal despite not being part of the EU, wouldn't that weaken the EU's position relative to other non-EU countries?
Yes. You'd have to think of what the EU really is: a group of countries working together on some shared values.
You could compare that to a club where members contribute to benefit from shared work. As such, it is obvious that club members don't want those outside the club (and thus not contributing to the same extent) to have the same or more privileges than those who do actively contribute.
As you note, it might work if a few people reep the benefits without contributing, but it doesn't work if the majority of people don't contribute but do reap the benefits.
In the EU example, we see that with the EU's red lines. Those are rules the EU has set for itself in the Brexit negotiation (and before that). A red line could consist of requirements on states that want access to the single market.
Is the EU 'punishing' the UK for Brexit? How so?
It depends on how you define punishing. Could the EU make it easier on the UK? Sure, they could just give into everything the UK wants. Will the EU do that? No, because it means creating an non-level playing field where the UK reaps most of the benefits (e.g. allowing the UK to make special deals with other countries that EU members cannot make while still allowing the UK to have access to all of the EU market).
Is the EU really punishing the UK? No, because those rules (even if not written down explicitly) were always there from the UK's signing on until now. Furthermore, with a bit of logic one can easily see that trade-offs will have to made on the UK side if the UK wants something different(=Brexit).