The squid's skin contains many cells of different colors. These cells are called chromatophores. Each cell can be made smaller or larger by the contraction of muscles. So the squid simply flexes the correct muscles to make the cells of the desired color larger and to make all the other colored cells smaller. And that makes the squid change color.
Photo courtesy of Photoshot Holdings Ltd./Alamy