When a container can is heated to a very high temperature, due to the thermal property of matter, it expands in size. It becomes bigger in volume. Of course it is hot and has more energy including the heat energy.
Now when cold water is put in to it suddenly, the temperature of the container, the heat energy flows from can into cold water. due to this the container loses its heat, and the temperature becomes less.
When the temperature becomes less, it contracts, shrinks in size and in volume.
During this process of shrinking if it happens suddenly, the can lose its shape.