What caused the long lasting of peace in during the Heian Period?
Like most things in history, it is never really just one thing. But, in essence, if we are going to provide a short answer -- it was the establishment of Heian palace in 794 CE by the strong and powerful emperor, Emperor Kanmu. Note that Emperor Kanmu's reign is from 781 to 806. History, however, records the Heian period from 794 to coincide with the establishment of this palace, also known as Heian no Miya (平安宮, "palace of peace/tranquility"). [see quote below]
The Heian period (794 to 1185 CE) started a trend of centralisation of political authority (the imperial court), beginning with Emperor Kanmu. It is known as the "golden age" of Japanese history because of these early "virtuous" emperors, of Kanmu, his son - Emperor Saga (809-23), and again Uda and Daigo (866-930). [see quote below]
This stability of over 4 centuries allowed Heian culture to flourish. The introduction of Kana was during this period, which greatly contributed to Japanese literature; The Tales of Genji by Murasaki Shikibu, which is still popular today, was written during this period.
For more reasons why this period is particularly peaceful, there is much to say about Japan's historical development during the Heian period, especially in the arts and political structure. So much that the multi-year work of The Cambridge History of Japan, out of 6 volumes, dedicated one entire volume (vol 2) to this period.
From the Introduction in vol.2, p.1 (emphasis mine):
The Heian period opened in 794 with the building of a new capital, Heian-kyo, later known as Kyoto. The grand plan of the new city, on a larger scale than earlier capitals, expressed the ambitious vision of Emperor Kammu. No other Japanese emperor had ever taken into his own hands so decisively the absolute powers of the emperor as conceived in Chinese theory. He and some of his immediate successors not only asserted the authority of the throne; they took positive measures designed to improve the effectiveness of the central government in administering the country. Theirs was a dedicated attempt to revitalize the system of administration modeled on the governmental machinery of T'ang China and operate it effectively. Throughout the four centuries of the Heian era the imperial court continued as the only political center, but the effectiveness of its administration declined gradually. The title of emperor continued in the imperial line without dynastic change, as it does to this day, but many of the reigning emperors were reduced to figureheads, manipulated by noble families at court, notably the Fujiwara, and later by senior retired emperors. The Heian period closed in 1185 when the struggle for hegemony among the warrior families resulted in the victory of Minamoto no Yoritomo and most political initiatives devolved into his hands at his headquarters at Kamakura.
Like all interesting narratives, the plot twist is the Heian period ended with the Genpei Wars (a fight for influence in a weakened Japanese imperial court). The winner established the Kamukura Shogunate which gave rise to the era of samurai wars.
Incidentally, there a was a question, which I answered, which focused on the cause of a weakened Japanese imperial court, Insei/cloistered rule (late-Heian) and rise of Daimyos - here.