Environment around the Sigiriya may have been inhabited since prehistoric times. There is clear evidence that the many rock shelters and caves in the vicinity were occupied by Buddhist monks and ascetics from as early as the 3rd century BCE.
In 477 CE, Kashyapa, the King’s son by a non-royal consort, seized the throne from King Dathusena, following a coup assisted by Migara, the King’s nephew and army commander. The rightful heir, Mugalan, fearing for his life fled to South India. Fearing an attack from Mugalan, Kashyapa moved the capital and his residence from the traditional capital of Anuradhapura to the more secure Sigiriya. During King Kashyapa’s reign (477 to 495 CE), Sigiriya was developed into a complex city and fortress. Most of the elaborate constructions on the rock summit and around it, including defensive structures, palaces, and gardens, date from this period.
Kashyapa was defeated in 495 CE by Mugalan who moved the capital back to Anuradhapura. Sigiriya was then turned into a Buddhist monastery, which lasted until the 13th or 14th century. After this period, no records are found on Sigiriya until the 16th and 17th centuries, when it was used briefly as an outpost of the Kindom of kandy
The Culavamsa describes King Kashyapa as the son of King Dathusena . Kashyapa murdered his father by walling him up alive and then usurping the throne which rightfully belonged to his brother Mugalan, Dhatusena’s son by the true queen. Mogallana fled to India to escape being assassinated by Kashyapa but vowed revenge. In India he raised an army with the intention of returning and retaking the throne of Sri Lanka which he considered to be rightfully his. Knowing the inevitable return of Mogallana, Kashyapa is said to have built his palace on the summit of Sigiriya as a fortress and pleasure palace. Mogallana finally arrived and declared war. During the battle Kashyapa’s armies abandoned him and he committed suicide by falling on his sword.
The Culavamsa and folklore inform us that the battle-elephant on which Kashyapa was mounted changed course to take a strategic advantage, but the army misinterpreted the movement as the King having opted to retreat, prompting the army to abandon the King altogether. It is said that being too proud to surrender he took his dagger from his waistband, cut his throat, raised the dagger proudly, sheathed it, and fell dead. Moggallana returned the capital to Anuradapura, converting Sigiriya into a monastery complex.
Alternative stories have the primary builder of Sigiriya as King Dhatusena, with Kashyapa finishing the work in honour of his father. Still other stories have Kashyapa as a playboy King, with Sigiriya a pleasure palace. Even Kashyapa’s eventual fate is uncertain. In some versions he is assassinated by poison administered by a concubine; in others he cuts his own throat when isolated in his final battle. Still further interpretations have the site as the work of a Buddhist community, with no military function at all. This site may have been important in the competition between the Mahayana and Therawada Buddhist traditions in ancient Sri Lanka.
The earliest evidence of human habitation at Sigiriya was found from the Aligala rock shelter to the east of Sigiriya rock, indicating that the area was occupied nearly five thousand years ago during the Mesolithic Period .
Buddhist monastic settlements were established in the western and northern slopes of the boulder-strewn hills surrounding the Sigiriya rock, during the 3rd century BCE. Several rock shelters or caves were created during this period. These shelters were made under large boulders, with carved drip ledges around the cave mouths.Rock inscriptions are carved near the drip ledges on many of the shelters, recording the donation of the shelters to the Buddhist monastic order as residences. These were made within the period between the 3rd century BCE and the 1st century CE.