Cognitive Maps in Language Models: A Mechanistic Analysis of Spatial Planning