For an ideal gas there are no interactions between molecules, so the internal energy is the total kinetic energy of all of its molecules. Compressing the gas increases the kinetic energy (and therefore also internal energy and temperature) of the gas, whereas allowing the gas to expand decreases kinetic energy.
When the walls of the container are fixed then the molecules which rebound from the walls have the same KE after rebounding as they had before. The velocity is reversed but the kinetic energy remains unchanged. The temperature of the gas neither increases nor decreases.
When you push down on the piston to compress the gas, the molecules rebound from the piston with a higher speed than when they approach it. Collisions with a piston which is moving towards the gas molecules increase the average speed of molecules and therefore also the temperature. When the piston is moving away from the molecules this reduces the temperature of the gas.
The fact that the piston usually moves very slowly (eg 1 mm/s) compared with the speed of gas molecules (about 400 m/s) might suggest that the motion of the piston can only have a miniscule effect on the speed of molecules. However, the high speed of the molecules means that there is a large number of collisions, each of which increases the speed of a molecule by a tiny amount, so the total effect can be significant.
eg In a container which has a height of 25 cm each molecule will collide with the piston around 800 times per second. If the piston moves for 5 cm at 1 mm/s that is 40,000 collisions per molecule, increasing its speed by a total of about 40 m/s, around 10%. Temperature is proportional to $v^2$, which increases by a factor of 1%. The temperature increases from 300 K by about 3 K.
The work done by the piston on the gas is the work done on its molecules. This is equal to the increase in the KE of the molecules, which is the increase in internal energy.
In a free expansion the volume of the gas is increased suddenly, without the molecules having time to collide with the piston. This does not result in any reduction in temperature. This shows that it is not the change in volume which changes the temperature of the gas but the work done by the piston, either imparting to or taking away kinetic energy from its molecules.