It was originally thought that St Margaret herself worshipped in this small chapel, but the style of the architecture indicates that it was built during the reign of David I, her fourth son, who ruled from 1124–1153.[3] The chapel formed part of a larger building, located to the north, which contained the castle's royal lodgings.[4]

On the night of 14 March 1314 the castle was captured by Robert the Bruce. He destroyed all the buildings in the castle, except for the little chapel. On his death bed in 1329, Bruce spoke of the story of Queen Margaret and issued orders for the chapel's repair, with some forty pounds Scots being put aside for that purpose. For many years afterwards the building was known as the "Royal Chapel in the Castle". There is a fairly frequent record of services held in the chapel, though another and larger chapel was also in use within the castle.

The chapel fell into disuse at the Protestant Reformation, and was used as a gunpowder store from the 16th century. By 1845 the chapel formed a store room at the western end of the 18th century garrison chapel, when the antiquarian Sir Daniel Wilson realised the significance of the chapel and publicised the building. The garrison chapel was demolished and St Margaret's Chapel restored in 1851–1852 with the support of Queen Victoria. The barrel-vault over the nave was added at this time, in keeping with the architectural style of the earlier fabric.[2] The architect Hippolyte Blanc proposed an enlargement later in the 19th century, but this was rejected.[2] The stained glass was installed in 1922. In 1929 further work was carried out to bring the chapel back into use, and the restored and refurnished chapel was dedicated on 16 March 1934.

The St Margaret's Chapel Guild was started in 1942 under the patronage of HRH The Princess Margaret and the leadership of Lady Russell. In 1993 as a commemoration of the 900th anniversary of the death of St Margaret, Historic Scotland renovated the chapel and St Margaret's Chapel Guild refurbished it with a new altar cloth, ten bench seats, an alms chest, a flower stand, and a display case for a facsimile of the St Margaret's Gospel book. Members of St Margaret's Chapel Guild now have a tradition of ensuring that there are always fresh flowers in the chapel to welcome visitors. Baptisms and weddings are held at the chapel.

The small irregular stone building has some similarity to earlier Scottish and IrishCeltic chapels. The rectangular structure with an internal width of 3 metres (10 ft) has an entrance door at one side near the back of the nave which is 4.87 m (16 ft) long, then a typically Romanesque round chancel arch 1.52 m (5 feet) wide with chevron mouldings decorating the arch above columns on each side leads into an apsed sanctuary 3 m long, with the apse having a radius of 1.52 m. The north wall has been renewed, and the three surviving outer walls are 61 cm (2 ft) thick, as is the chancel wall. Five small round-headed windows and the round arch above the entrance door confirm the Romanesque style.