I can't say that this applies to every tunnel imaginable, but this is a general idea how this could work.
A tunnel is set up between an entry point and an exit point. In this case the outer packet will have entry point as a source address and exit point as a destination address. The exit point will receive a packet with itself as a destination address. Thus the exit point knows that it doesn't have to forward packet, but instead needs to process it.
After the exit point has determined that it is responsible for packet processing, it needs to know what to do with the packet. Usually, the next thing to do is to determine what the next header is and parse it[*]. In IP (that is if the outer header is IP), what the next header is, is specified in protocol field (IPv4) or next header field (IPv6). For example, if the inner header is IP then the protocol field is set to 4. Other tunneling protocols will have different values.
So, in the example of IP in IP, the router can determine that it has received an IP packet destined to itself which contains another IP packet inside it. Then the router does what is written in the tunneling protocol specification.
[*] This is actually what every system does when it receives a packet with itself as a destination address. It checks the protocol/next header field to determine what further processing the packet needs.
Note: tunnel does not have to be "over IP", there are tunnels over L2, L3, or L4 protocols. The general principle is the same, outer header has to have some field identifying inner header. L2 and L3 protocols usually have an equivalent of "next header" field, e.g., Ethertype in Ethernet. L4 protocols differentiate data flows by ports.