Mitarai Tenmangu is located at the back of what used to be the main brothel area of Mitarai, and was popular with the working girls.
Legend says that the mythical Empress Jingu stopped at the well here and washed her hands and that this is where the towns name came from. In the Meiji period a Tenmangu shrine was built here supposedly as Sugawara Michizane also stopped at the well and washed his hands.
The fact that Tenjin was not enshrined here until Meiji suggest to me that maybe it was a strategy to protect the local shrine. In late Meiji the government set about closing down half the shrines in the country, mostly local, nature based shrines. One way to stop your shrine being closed down was to enshrine a "national" god , like Tenjin.
There is a curious monument to a local Mitarai man, Harukichi Nakamura, who was the first Japanese to cycle all the way around the world. which he apparently did in the early years of Meiji.