I know nothing of the temple in Azerbaijan but Persia had its own religion that formed out of early Hinduism around the 5th century BCE by the name of Zoroastrianism so many temples would be temples for that religion. Then you later had the Arab Conquests which, at first, were pretty tolerant but as more and more of the population converted those that followed Zoroastrianism were taunted and buildings were once again being converted to another religions use (or outright destroyed like a venerated Cypress tree in Khorasan). Hinduism as a whole though spread far and wide through trade as we see in the rest of Asia such as Southeast Asia and even China (though both regions were later dominated by Buddhism).