If a sample of gas is compressed (the volume is decreased, without changing the amount of gas contained), the same amount of gas is confined in a smaller space. The gas particles do not travel as far or as long after a collision with the wall before colliding again. Therefore, the number of collisions (per unit time) with the walls from these gas particles increases, and the pressure will also increase.
If the gas is expanded, the pressure will decrease since the particles will be able to travel farther between collisions, reducing the number of collisions per unit time on any part of the container.