What is thought by the undergraduate curses of Thermodynamics is really Thermostatics. It discusses the equilibrium states. The state variables are defined for equilibrium. Only those processes can be treated in the frames of Thermostatics which are so slow that practically go through equilibrium states. These processes are reversible. Other processes are treated in the frames of Non-equilibrium Thermodynamics or Irreversible Thermodynamics.
In this problem, the first stage of this process is very fast. The gas molecules are pushed by the piston and gain some extra momentum in the direction of the piston, so the distribution of velocity is not random any more unlike it is in equilibrium. If the gas is not in equilibrium with itself you can not define pressure and temperature or internal energy. After the piston stopped, the gas gets into equilibrium very fast and the First Law applies between the initial and final states: The change of the internal energy is equal to the added heat plus the work done on the gas by the external forces. No heat is added as the walls prevent fast heat transfer. The work done is not integral (-PdV) but the integral of the external force between the initial and final positions of the piston. This work is positive, so the gas gained energy. The amount of the gas stayed the same, and if it is ideal, U=Cv n T. If U increases, so does the temperature. Knowing the initial and final volumes and the work done by the external force, you can find the final temperature and pressure for the first stage of the process. The next stage is slow: heat transfer through the walls. The gas reaches equilibrium with its environment at the end, its temperature becomes equal to the external temperature. As PV/T is the same for the initial and the final states, and the final temperature is lower than the initial one, so is the pressure.
If the piston moves relatively slowly so the mass elements of the gas are in local equilibrium, for special problems you might determine the local volume, pressure and temperature during the compression, knowing how the piston moves and the heat transfer properties of the gas and the walls and you might determine the heat transferred. But this is the topics of Irreversible Thermodynamics.
ehild