History and story of the temple:
Lord Brahma (the first of the three main gods of Hinduism) is said to have gotten cursed by Lord Shiva for falsely stating that he had seen Shiva's head. And as an effect of the curse, Brahma was forced to take upon a human form as a priest's son in the small town of Virinjipuram.
After losing his father at a young age, the small boy was forced to work and feed his family by taking up temple duties. The child got his upanyayanam (thread ceremony) done by Lord Vishnu himself in front of the Selva Vinayagar Sannidhi (another name for Lord Ganesh, who is Lord Shiva's son)
Since the child was too small compared to the height of Lord Shiva's Lingam, it is said that the Lord mercifully bent his head to help the child in the North-East direction. And once this happened, Lord Brahma was relieved from his curse and was allowed to go back to his godly form.
**The place got called Virinjipuram since Virinji is another name for Brahma
There are multiple other stories associated with the temple. For example, the Lord saves a merchant from dacoits who loot him and accompanies him to safety(thus the name Margabandeeswarar), stories around the Lord protecting against black magic, etc.
The shrine is famous for young Brahmins (a sect of Hindus) coming and having their thread ceremony here during the November-December period. You can also witness the 10-day Brahmotsavam festival with the flag hoisting ceremony where the deity is taken on a procession around the temple during the Indian month of Panguni (March-April).