In a piston cylinder why do particles lose kinetic energy when doing work (expansion) in the piston, when the system is heated? When I push a piston in a cylinder downwards, I'll give more kinetic energy to the particles. That's easy to understand. But, what if I transfer heat to my system in order the gas to expand, why does particles lose kinetic energy? I know that the heat goes to the system, and this energy is then converted in work on the piston. But, why particles lose kinetic energy when pushing the piston?  
 A: You push the piston down, you give KE to the gas. The gas pushes the piston back up, the gas gives KE to you. It is just the reverse of the same process.
The gas particles gain KE because they are bouncing off an object that is moving towards them. They lose KE when they are bouncing off an object that is moving away from them. 
These are elastic collisions (total KE is conserved) so the law of restitution applies : relative speed of approach equals relative speed of separation. When the piston moves down at speed $u$, and the gas particles approach it with perpendicular speed $v$, the relative speed of approach is $v+u$, so the gas particles rebound with speed $v+2u$. Their component of speed in the direction of the piston motion increases by $2u$ from each collision with it. 
At room temperature the speed of air molecules is already around $\sqrt3 v=460 m/s$. The factor of $\sqrt3$ arises because the molecular speed has equal components $v$ in 3 perpendicular directions. So $v=266m/s$ in one direction. If the vessel is $0.5m$ across the particles collide with the piston 266 times per second. After one second (266 collisions) their speed increases by $2u+4u+6u+...+532u=2u(1+2+3+...+266)=71,000u$ approx. If u is only $1mm/s=0.001m/s$ this is an increase of 71m/s in the direction of the piston. 
The gas "thermalises," sharing this increase with the other 2 component directions; after such "thermalising" the increase in each direction is $\frac{71}{\sqrt3}=41m/s$. Absolute temperature is proportional to $v^2$ so temperature increases to $300K\times (\frac{266+41}{266})^2=400K$ during this compression.
If the gas is expanding, the component of speed of the molecules decreases by the same amount of $41 m/s$, so the temperature falls to $300K\times (\frac{266-41}{266})^2=215K$ during this expansion.
My calculation illustrates how a piston moving at 1mm/s can have a significant  effect on the speed of molecules which are already moving at about 460m/s. It does not attempt to be rigorous. For example, I have assumed that thermalisation occurs only at the end of the expansion/compression, but it may happen during, which reduces the change in temperature. 
