I am under the impression that the various Japanese bakufus or shogunates, be it Edo or Kamakura, were very keen on Buddhism, so that there have been temples built by the shoguns (generals) such as Kinkaku-ji. On top of that, there have also been offspring as well as samurais becoming monks to either conceal their identities or simply to pray for graces of the gods. Why were there such bonding relationships between bakufus and Buddhism? How deep were those relationships?
This is a really broad question, and as a result, there's not a single satisfying answer. It's very much analogous to asking, "What was the relationship between Christianity and the governments of Europe before the 1860s?"
There were many different sects and varieties of Buddhism that rose and fell throughout Japanese history, after the original version was first imported in the 6th century CE. Since then, some of those sects have gained massive prestige through ties to certain social classes, and even became major political players on their own. Some governments were tied deeply to Buddhism, while others ignored or even reviled it. But you could also look at the role of Buddhism in government not just at the sect level, but even at the level of a single monastery or individual.
For a few scattered examples of the ties between Buddhism and Japanese government / politics throughout history:
Buddhist monasteries essentially started the trend of asking for and receiving tax-free grants of land (aka Shoen) from Emperor under the Ritsuryo system of land stewardship, one of the earliest forms of centralized land management by a government. As the number and size of Shoen continued to grow, this led to the financial--and then political--instability of the court, which is one of the many reasons considered important in the transfer of power from the Imperial court to warrior-led governments.
Shingon Buddhism, also known as Esoteric Buddhism because of the ornate and difficult-to-follow rituals required of its participants, was tightly tied to the Imperial court of the Kamakura period. Important people, therefore, would use their allegiance to it or other sects or none of them as a kind of political statement.
Buddhism was largely the domain of the rich, powerful, or noble through most of its time in Japanese history. During the Sengoku Period, this changed with the rise of the Ikko Ikki, which is very hard to encapsulate in a small space, but essentially were Buddhist uprisings/vendetta groups called Ikko, all nominally tied to a single sect of Buddhist: Jodo Shinshu. Many of them were spontaneously formed by peasants, and as they joined together, they became a large military, economic, and political force during this turbulent time, even wresting complete control of the Kaga Province and instituting a weird populist blend of communistic and feudal government.
The Tokugawa bakufu was actually rather hostile to Buddhism, especially early on. The political philosophy that ended up promoted was by and large neo-Confucianism. These ~200 years are considered a very low period for Buddhism in Japanese history.
Buddhist allegiance was actually a form of protest in Okinawa in the early 20th century, in reaction to state-compelled participation in Imperial State Shinto, where the Emperor was literally a figure of adoration and worship. Okinawan nobility were staunch Buddhists or Confucianists, while lower classes had their own animistic practices; Shinto in any form was entirely foreign. Besides being religiously oppressive, it was also used as a way to force assimilation of Okinawans and destroy "uncivilized" practices. Thus, openly advocating for Buddhism became an act of political rebellion.
In post-war Japan, Nichiren Buddhism was one of the few vehicles that managed to shelter among the upper classes the mindset of Imperial Japan at its worst through both American top-down and Japanese grassroots attempts at eradicating it. To this day, there remains close ties between politically conservative ultra-nationalists and Nichiren Buddhism.
To add to /u/churakaagii 's comments for the Edo Period: 1600-1868. By the early 17th century, the independence and power of Buddhist sects had been severely curtailed, a lot of properties had been stripped from monasteries etc. Neo-Confucianism did indeed capture the minds of the governing class, and Confucianism has an in-built tension with Buddhism.
But there was a bit of an upside for Buddhism in Tokugawa Japan: the Tokugawa shogunate policy that every single person must be registered with a local Buddhist temple, and be buried with Buddhist rites: an ongoing source of money to local temples. These locals were also required to support that "parish" temple when it asked for donations and support.
The intent of this policy was to crack down on Christianity, but it continued throughout the era, long after Christianity had vanished/gone underground in a few last places. Later Edo Period tensions over this policy were between Buddhists and Pure Shinto practitioners. Luke Robert's Performing the Great Peace has a good chapter on the strife and workarounds regarding funerals for anti-Buddhists. One solution he records for Pure Shinto priests was to have a Buddhist official funeral where there was no body inside the coffin, and the "real" funeral according to their own rites.
The Tokugawa shogunate also were patrons and commissioners of their own large mortuary temple complexes, and of other significant temples, all built to support their own glory and importance. So, Tokugawa Buddhism was not the high point of Buddhist power and independence, but for many government-favoured Buddhist temples, monasteries etc. a very comfortable period.