“O son of Kuntī, a person freed from these three gates of darkness acts for the welfare of his ātman and then reaches the highest destination.”
Going deeper
16.21 says that desire, wrath and greed are the three gateways to Naraka, ruinous to the self, and that therefore one should abandon these three. 16.22 takes up the same gates, now called gates of darkness, and follows the person released from them. One released from these three works for the benefit of the self, and thus reaches the supreme state. So the chain runs: desire, wrath and greed, release from them, work for the benefit of the self, the supreme state. Kṛṣṇa speaks these verses near the close of chapter 16, addressing Arjuna, after 16.20 has described deluded men who sink down to the lowest level. 16.23 gives the contrast: one who abandons the injunctions of the Śāstras and acts under the influence of desire attains neither perfection nor pleasure, nor the supreme state. The same supreme state closes both verses, reached in the one and missed in the other. See what the Gītā says about liberation.