Main explanation(s) from Swedenborg's works:
Inner Meaning of Prophets and Psalms 273
Other references by Swedenborg to this story:
The 23rd Psalm is one of the best-known and most-loved literary works in the world, and it may well be the best poem ever written. It is also a fine example of the power of figurative language: We read deep things into the vision of ourselves as sheep, led to green pastures and good water by a kind shepherd. It’s empowering to feel the confidence to go fearlessly into the valley of the shadow of death, and to feel the love and caring of a table prepared by the Lord and a cup so full it overflows.
What people don’t know, however, is that this language actually has precise internal meanings, and that when we see them there is an even deeper beauty in the poem. That’s because what it actually describes is the path to heaven, and the fierce desire the Lord has to lead us there.
The first step is to let the Lord be our shepherd – to accept His teaching and His leadership. The green pastures and the still waters represent the things He will teach us for the journey. Then He begins working inside is, setting our spiritual lives in order, so that we desire to do what’s good and to love one another. That’s represented by restoring our souls and leading us in the paths of righteousness.
But we will still face challenges. We still live external lives, out in the world, and we are subject to desires that arise in those externals, in our bodily lives. That’s the valley of the shadow of death. But the rod and staff represent truth from the Lord on both external and internal levels, ideas that can defend us against those desires.
And if we keep following, the Lord will prepare a table for us – a place inside us that he can fill with love (the anointing oil) and wisdom (the overflowing cup). Thus transformed, we can enter heaven, with love for others (“goodness”) and love from the Lord (“mercy”) and can love and be loved to eternity.
One of many beautiful things about this is the fact that it is the Lord who really does all the work. In the whole text, the only action taken by the sheep is walking through the valley of the shadow of death. Other than that, they follow the Lord, trust the Lord, accept the blessings of the Lord. And that is really true! In external states (in the valley) we might seem to be doing the work ourselves, but internally, spiritually, we simply need to give ourselves to the Lord and let Him bless us.
The underlying idea here is that the Lord created us so that He could love us, in loving us wants us to be happy, knows that our greatest happiness will come from being conjoined to Him in heaven, and Himself wants nothing more than to be conjoined to us. So everything He does, in every moment of every day for every person on the face of the planet, is centered on the goal of getting that person to heaven. He wants each and every one of us in heaven more than we are capable of imagining. We just need to cooperate.