Your lightning channel is a 2 of 2 multi-sig smart contract. Each peer has the option to close a channel at any time because both parties have access to the fully signed, but unbroadcasted close transaction at all times. To close a channel means to allocate the funds in a channel back to the bitcoin base layer. These funds that you own (or would be considered your ‘outbound’ or ‘local’ funds) will then be deposited into your LND on-chain wallet.
Every time the balance of a channel changes, each peer signs an on-chain transaction updating the contract. Each peer then stores the signed 2 of 2 transaction if a closure is requested by either peer.
In the event of a cooperative close, one would broadcast the signed transaction, also known as a commitment transaction, to the bitcoin network. They would choose the fee rate and the channel would close and each peer would receive what they had on their side of the channel on-chain.
In the event of a unilateral close, this transaction enters a time lock state which will allow the other peer to contest the close if it is representing a channel state with a timestamp before the timestamp of the other peer. An uncooperative close also allocates more funds for the on-chain fee to be absolutely sure the transaction will confirm on-chain. An uncooperative close is usually initiated by a node runner whose peer has been offline for a long amount of time and is unlikely to return. If a node attempts to broadcast a channel state that is not the most current one, and the other peer comes back online, they will detect the attempted cheat and the network will allow the cheated peer to have the total amount of funds in the channel.
Another way to protect your node should your node go offline is to have another node on the network watch your node. These are called watchtower nodes and are completely invisible on the network. Because of this, node runners are incentivized to not cheat their peers because the punishment is grave and there is no way of knowing if their peer has a watchtower active.