Phonosemantic compound. 又 represents the meaning and 之 represents the sound. Based on the original meaning "to hold", now written as 持. The current meaning "temple" is a phonetic loan.
又 hints at the original meaning of 寺, "to hold",
which is no longer the most common meaning of 寺 in modern Mandarin.
Character Evolution
BronzeLate Western Zhou~800 BCBronzeLate Spring and Autumn~500 BCBronzeEarly Warring States~400 BCSealLate Spring and Autumn~500 BCSealWarring States (Chu)475-221 BCSealWestern Han202 BC-9 ADSealShuowen~100 ADClericalQin221-206 BCClericalWestern Han202 BC-9 ADClericalEastern Han25-220 ADRegularModern