When you pour in the hot water, it takes up all of the space inside the bottle (since it is a fluid). When you pour out the hot water and quickly put on the cap the air pressure inside the bottle is less than the air pressure outside causing the bottle to implode on itself. I'm not really sure about pouring cold water on after, maybe someone knows the answer to that part. But if you try doing it you can probably figure out what the answer is!
When you pour the hot water in, and then out of the bottle the air that rushes in to replace the water is warmed by the water, and the warmed sides of the bottle, causing it to expand and some air leaves the bottle. When you then cap the bottle and let it cool to room temperature the air inside contracts, but because the cap is on no air can get back in to even things out. This causes the pressure inside the bottle to drop. Because the outside air pressure is higher than that inside the bottle, the bottle will chrush in, if it is plastic, until the bottle is small enough that the two pressures are equal. Pouring cold water on the bottle just amplifies the contraction of the air inside the bottle causing an even more pronounced effect. Note that this can be hazardous if you use glass, because the glass will not bend or crush but appear normal until the pressure difference gets to high and the glass simply implodes all at once.