How can pin states be altered by using JTAG Instruction Codes?
The JTAG circuit elements are embedded into the design of the chip which supports it. The boundary scan feature and ability for JTAG to access the pins is by hijacking the control from the MCU and being the middle-man between it and the outside world. This allows for full hardware testing with a blank MCU in a large digital system which is really cool for Quality Control and testing processes prior to bringing up a MCU with firmware for the MCU's round of self-testing. 

The JTAG interface like I said is a sort of integrated logic module which sits between the MCU and each of the the external pins/ports. 

I suggest you read more about the JTAG interface and the instruction set. The good part is that any MCU or device which supports JTAG is meant to be consistent and standard in the way they interface with JTAG. Read the documentation and play around with it!