Your confusion stems from some incorrect assumptions.
But surely, the only device that knows this routing mechanism is Router-C itself! Not even Computer-A nor Computer-B will know about it, right?
What, why‽ Then why was the router configured to forward those ports to those IPs? You have to set up the P2P client to use a specific port and then set up the router to correspond.
but how is Router-D to know to send packets through port 1000, and not say port 1001?
Because you configure the P2P client to use a specific port (standard or non-standard for that protocol).
The only solution I can think of is for Router-D to send the packet to Router-C through all ports, such that it gets forwarded to Computer-A, but is there a better solution?
It is much simpler than that. When the client makes a connection to a peer, it specifies which port it wants to use, so the peer sends the data on that port.
Hmm, but Bittorrent doesn't change the router's behavior right? Since some routing mechanism could have been dynamic as demonstrated in superuser.com/a/187190/78897, how is Computer-A able to know about it?
The client doesn’t directly affect the router, but the router can be configured/intelligent enough to adapt to the client’s behavior. You can enable UPnP in both the router and client to automatically configure the connection and most routers have stateful inspection abilities as part of their port-forwarding mechanism.
Take together, what it means is that a connection can be dynamically made on a random port, and then the router can keep track of what is happening instead of viewing everything as random, meaningless connections. That way, it can forward a connection as necessary because for example, it is a response to this other connection that just happened.
The problem comes when you have multiple systems using the same program. Having multiple systems connected to the same router, sharing the same IP and using dynamic ports quickly becomes unmanageable and even with stateful inspection, it is difficult if not impossible to get it to work correctly. In that case, static ports (default or otherwise) will need to be used.
If you use a program like SmartSniff or TCPView to monitor your connections, you will notice that the P2P connections will usually have the port you configured (or the default for the client) as the destination for incoming connections and either the default or a custom/random port for the source, and vice versa for outgoing connections.
The different networking layers are there to allow them to be swapped for different technologies.
The two layers you are talking about here are layers 2 and 3. Layer 2 in this scenario is Ethernet - from which MAC addresses arise, and Layer 3 is IP.
Ethernet only works at the local level, between network devices connected to a broadcast network "datalink", whereas IP is a routable protocol and so can target devices on remote networks.
The requirements of each of these are different. Ethernet specifies a family of technologies that allow packets to be sent and received between network devices, whereas IP defines a protocol that allow packets of data to traverse multiple networks.
Neither is reliant on the other, which is what give networking its flexibility. For example, you may choose to connect to your internet service using IP over ethernet, but in your internal network, you might choose to use IP over... paper. Where someone writes down the contents of each packet and physically walks it over to another machine and types it in. Clearly this would not be particularly fast, but it would still be IP provided the person carrying around the bits of paper respecting IP routing rules.
In the real world there are different datalink protocols that you are already using two different ones (although their addressing schemes are the same): 802.3 - ethernet, and 802.11 - wifi.
IP doesn't care what the underlying layer is.
Equally, IP can be swapped out for different network layer protocols (provided it happens for all participants). Such as ATM.
While there is nothing directly preventing the creation of a protocol that encompasses both layer 2 and layer 3, it would be less flexible, and so less attractive, and so unlikely to be used.
Best Answer
In a nut-shell, when a router doesn't know how to route a packet it'll send the packet to the default gateway/the next "hop".
Basically, when your router can't find a valid rules (or more formally, it's route table) it will send the packet to the default gateway, which will typically send it upstream to your ISP.
Once the packet arrives at your ISP's routers, much like your own router, they will have their own route tables. But this time they'll be more detailed. Knowing about other customers and other ISP's.
This will continue on until the final router that has the final destination rule attached to it, sending it onto the specific computer/Interface.
All along this way, the packet includes source information indicating where the original packet came from. Your router (likely, with NAT) would had converted this source information from your local machine's internal only IP address (e.g. 192.168.1.25) to your WAN IP address given to you by your ISP (e.g. 121.147.148.55) and this WAN IP will be what's contained within the packet's source information.
Thus, all the upstream routers can simply perform the same routing as above, but in reverse to send your packet back to you. However, once it reaches your router. Your router has it's own special rules to know that that certain packet should be forwarded back to your local machine with it's internal only IP address. This is called Network Address Translation.