How can one say pressure is constant in thermodynamics?
Sometimes in thermodynamics we wish to constrain pressure to be constant.  [Or we may wish to do a thermodynamic analysis for a system that is at constant pressure, which is a common laboratory condition.]   However, that is a choice.  Pressure is not generally constrained to be constant in thermodynamics.
For a closed system:
$$d\text{U} = \text{đ}q + \text{đ}w$$
[Note that I'm using a different sign convention from you for work, but the results come out the same.]
If the only type of work is $pV$- work, then  $\text{đ}w = -p_{ext}dV$, where $p_{ext}$ is the external pressure applied to the system by the surroundings.  Thus we have:
$$d\text{U} = \text{đ}q - p_{ext}dV,$$
where the pressure can change in any way you please during the process.
If the process is reversible, then (in that idealized case) the system is in continous equilibrium with its surroundings. As as a consequence, $p_{sys} =p* = p_{ext}$, and we can write:
$$d\text{U} = \text{đ}q - pdV$$
[*The convention is that if a subscript is not present, the variable is assumed to apply to the system.]