The shrine here is Iga Hachimangu (Hachiman Shrine). It is dedicated to Hachiman, the god of war, and was a special shrine for the Matsudaira family. Tokugawa Ieyasu’s grandfather moved the shrine to Okazaki from Mie and it was built up to it’s current form by Ieyasu’s grandson, Iemitsu.
The Matsudaira and Tokugawa lords would come here before major battles to pray for victory. When praying for victory, the armies would stay at the shrine until the torii gate at the entrance (in the background of the above photo) moved, signifying Hachiman’s blessing. Knowing this and wanting to boost morale, Ieyasu would order ninja from Iga Province to secretly move the torii at night. Clever guy, eh?
Read more at JapanDave.com