If two parties that want want to pay each other on the Lightning Network are not directly connected by a payment channel, but are each connected to another party, that party may act as an intermediary between the two.
For example, Bob wants to pay Alice but they don’t have a channel open. However, both Bob and Alice have a payment channel open with Charlie. So Charlie can act as an intermediary to facilitate transactions between Bob and Alice. Theoretically, transactions can bounce through an unlimited amount of intermediary nodes. Intermediaries are what makes the Lightning Network a “network”.
Since LN transactions have various security protocols, like HTLCs, Charlie cannot access or steal the payments for Bob and Alice when it travels through his node. This allows payments to route in a trustless and non-custodial way, guaranteeing that the bitcoin either gets to its final destination or the initial party gets its bitcoin back.
- Lightning Network – Bitcoin Wiki