Why do some temples have dress codes?
to keep the atmosphere traditional and respectful; follow the code of each temple as a guest would.
Each temple is run according to its own Āgama and local custom, and many of the old temples of South India and elsewhere ask visitors to wear traditional dress. In several Kerala temples men wear a dhoti (mundu) and remove their shirt, covering the shoulders with a cloth, and women wear a sari, salwar or long skirt. Some temples in Tamil Nadu, Karnataka and Maharashtra ask for no shorts, jeans or sleeveless tops.
The reasons given are respect and simplicity: traditional clothing removes the display of wealth and fashion, puts all devotees on the same footing, and keeps the mind on the deity. Bare-chested entry in some temples is also explained as humility before God.
Check the temple's official website or notice board before you go; many big temples rent or sell a simple dhoti or shawl at the entrance. If you are unsure, modest clothing covering shoulders and knees is always a safe choice.
Source: Āgama tradition; temple rules · Check the temple's notice before visiting
Dharma Q&A — vratas, festivals & temples · Ask a Jyotishi your own question