Till which layer does the loopback packet goes?
When you say "layer", you are probably thinking of the OSI model, also known as the seven-layer model.

However, real TCP/IP implementations don't actually fit the OSI model very well.  The OSI model was designed by a standards committee 30 or 40 years ago, based on how the committee members thought network stacks ought to be designed -- but that was before the Internet and without the advantage of the experience we have today.

127.0.0.1 is an IP address, and the loopback functionality of 127.0.0.1 is associated with the IP protocol.  The IP protocol can be thought of as most closely associated with the "network layer" (in the OSI model).  So, you could say that the answer is "the network layer".

But, it's important to realize that this is a bit of a lie.  In real operating systems, there's not necessarily a clean separation between the TCP stack and the IP stack; the two are closely hooked together.  So, it's doesn't make sense to ask "the code that does loopback processing -- what layer is it at?".  The code that does loopback processing could plausibly be considered part of the TCP/IP stack, and the TCP/IP stack combines elements of the network layer, the transport layer, and the session layer.  Loopback processing might also be performed in a separate device driver that, from the operating system's perspective, looks like another device (just like another Ethernet card, but different), so one could even make an argument that the code is really part of the data link layer or physical layer.  See how the seven-layer OSI model isn't really adding much insight here?  The code is what the code is; trying to attach a label based on one of those seven layers is a human construct, one that in this case isn't a very good match to reality.

It's probably better to think of the OSI model as a plausible vocabulary for talking about network protocols, but it's less helpful when talking about the structure of networking code: the structure of the code doesn't necessarily correlate well to the seven layers of the OSI model.

TL;DR: the OSI model is a lie.