We study the pinning quantum phase transition in a Tonks-Girardeau gas, both in equilibrium and out of equilibrium, using the ground-state fidelity and the Loschmidt echo as diagnostic tools. The ground-state fidelity will have a dramatic decrease when the atomic density approaches the commensurate density of one particle per lattice well. This decrease is a signature of the pinning transition from the Tonks to the Mott insulating phase. We study the applicability of the fidelity for diagnosing the pinning transition in experimentally realistic scenarios. We find that fidelity can predict the particle number(s) at which the pinning occurs. In addition, we explore the out-of-equilibrium dynamics of the gas following a sudden quench with a lattice potential. We find that all properties of the ground-state fidelity are reflected in the Loschmidt echo dynamics, i.e., in the nonequilibrium dynamics of the Tonks-Girardeau gas initiated by a sudden quench of the lattice potential