Sancho I founded a church here in 1186, probably on the site of the mosque, to serve the alcaides of the town and the garrison; when the court was in residence it doubled as the chapel of the queens, Óbidos being part of their personal estate. Be clear about what survived: the 1531 earthquake damaged it and the 1755 earthquake destroyed it. What stands is the rebuild begun in 1765 and finished in the 1770s, on the old site and to a very different, plainer design. Afterwards it was deconsecrated and left empty for a long time.
In 2013 the Ler Devagar operation, working with the municipality’s Vila Literária programme, put a bookshop into it — Óbidos has been a UNESCO Creative City of Literature since 2015, and this is the flagship of a network of bookshops installed in odd buildings around the town, including the old market hall. The shelves are freestanding timber structures set down the nave, and books are stacked where the altar was. There are film screenings, launches and exhibitions.
The reason to walk in is not the stock, which is mostly Portuguese with an English and Spanish shelf. It is that this is the only large historic interior in Óbidos you can stand in for as long as you like, for nothing, without being moved along. The castle is shut, Santa Maria closes over lunch, and the streets between about eleven and five belong to the day-trip coaches. This building is open through the middle of the day, has a roof, and nobody minds how long you stay.
It is at the top of Rua Direita in the Cerca Velha, immediately below the entrance to the castle, so it is thirty seconds from one of the two stairways onto the walls. If it is raining, this is where to go and wait it out.