Long before it became a mosque, the building now known as the Koça Mustafa Pasha Mosque had an intriguing past. Originally constructed in the early 5th century, it began as a monastery dedicated to Saint Andrew the Apostle. Over time, the site gained additional significance when, in 766, it became the burial place of Saint Andrew of Crete. The church was then re-dedicated to this revered figure.
The structure saw several periods of rebuilding. In the late 9th century and again in the 13th century, the building underwent significant restorations. Each phase added new details and character to the architecture. Major change arrived in the late 15th century, around 1490, when the church was converted into a mosque during the Ottoman era.
From the 16th century onwards, the mosque was used by the Dervishes, known for their mystical religious practices. During this time, a fascinating legend emerged involving a chain and an old cypress tree in the mosque’s courtyard. It was said that the chain could reveal the truth: when swung between two people who disagreed, the chain would strike the honest one. Today, visitors can still see the stump of the ancient cypress, a quiet reminder of the stories that live on in this historic space.
Source - https://en.wikipedia.org/wiki/Koca_Mustafa_Pasha_Mosque