I think that's the whole point.
Rick has become a certain person, and that person was forged outside the wall. It's the world outside that makes us what we are - not the fantasy world contained within. When we lose our understanding of what exists outside of our walls, we risk getting trapped within, forgetting about the true reality of existence that surrounds us. The people of Alexandria are almost completely detached from reality. Their focus is on a fragmented and limited aspect of an old way of life that, quite frankly, no longer exists. Their worries, as Sasha eloquently pointed out, are of things trivial and mundane, like making the wrong kind of meal for someone...
Rick recognized his attachment to this false reality when he reached for his gun as Pete and pretty-face walked away. To remind himself that this attachment was only temporary, he retreated to the wall, and almost embraced it. I think doing so was not too dissimilar to praying for religious people.