How is the state of a GPIO pin detected?

A HIGH and LOW are simply a voltage with in the case of TTL High being anything over 3.7V and LOW being anything under 0.7V.

You make electronic circuits that take combinations of these voltages and make logic functions. The simplest being a NOT a circuit whose output is NOT the logic level as the input. The next circuit is an OR gate where the output is HIGH if one OR the other of two inputs are HIGH.

That is it.

All other logic functions are derived from those two concepts. All memory, counters, latches, everything in digital electronics is a combination of those two functions.