Does upgrading after all locks and before all unlocks violate 2PL?
It's allowed.
You can upgrade any locks during the growing phase, and downgrade any locks you want during the shrinking phase, and it's a valid 2PL. What you can't do is release/downgrade during the growing phase, or acquire/upgrade during the shrinking phase, because this breaks the phase ordering rule.
Note that even during the shrinking phase, downgrading breaks strict 2PL, because it releases an exclusive lock. More on this in a moment.
I think the reason why you may be asking is that your example transaction reads Y, then upgrades, then writes Y. You may be wondering what happens if some other transaction holds a shared lock on Y, and also wants to upgrade.
This is a deadlock situation, so one of them wins and the other transaction is aborted, or rolled back to at least the point where the shared lock on Y was acquired. The lock upgrade operation can and does cause aborts. Similarly, downgrading can cause cascading aborts, which is yet another reason why most database systems prefer strict locking.