First we should probably clarify that while the term "Sakoku" or "closed country" appears in many popular histories of Japan, it has fallen into some disfavour among academics on the subject. Instead the term "kaikin" or "seaborne/maritime prohibitions" is used to more accurately characterise the policies of the shoguns at the time. This isn't merely some technical squabbling over semantics, it impacts conclusions historians can reasonably draw about the reasons for the policy in the first place. It was not intended to destroy all international trade or even to actually completely isolate Japan from international affairs. Even early on, China acknowledged Japan as a potential threat due to its rapid adoption of many new ideas and technologies (Arthur Tiedermann, Modern Japan).
So then, what were the reasons for trade, migration and cultural diffusion being so heavily restricted?
External factors caused by pressure from European colonial powers. European colonisation was among the world's most poorly kept secrets. The Spanish in the Philippines, the Dutch in Indonesia and pretty much everyone in China had all made efforts throughout the 16th and early 17th centuries to either wrangle ludicrously imbalanced trade deals, construct highly influential trading outposts or else outright invade and colonise. Empress Meisho is recorded as having expressed doubt as to the intentions of Europeans so it's known that those in Japanese elite circles certainly considered this a factor.
External factors relating to China. More modern research has made claims (at least somewhat supported) that Sakoku was a deliberate strategy by the shoguns to establish a firm presence for Japan in the geopolitics of East Asia that simultaneously allowed for contact with China, particularly through the Ryukyu Kingdom as a buffer state) while also maintaining independence from China (and particularly ruling out any kind of vassal state relationship) (Tashiro, Foreign Relations During the Edo Period).
Ideological reasons. Shogunate rule was quite conservative ideologically, with frequent reinforcement of feudal norms in the face of a changing society. In particular, this involved glorification of the agrarian lifestyle and honouring feudal relations such as those between peasant and landowner. Western norms presented challenges to this ideology, and there is some argument that Christianity, by its core beliefs, also challenged the supreme position of the shogun. It is difficult to determine how prominently this featured in the reasoning of the Bakufu, but the sheer level of destruction of any outside cultural influences suggests that it played some role in their logic.
Internal challenges to the shogunate. Despite this ideology, the shogun was by no means unassailable (as proven later with the Satsuma-Choshu alliance). Prominent daimyo presented significant threats to the status quo, with some growing exceedingly wealthy through international trade. By implementing Sakoku, all international trade was performed on the shogun's terms. This restriction on the activity of the daimyo was not unprecedented and definitely formed part of a deliberate strategy to centralise power under the shogun and government (Tiedemann again).
Internal threats from other classes. Christianity was being adopted quite rapidly by certain sectors of Japanese society, particularly the urban poor and parts of agrarian society. Compounded by other factors (drought, the development of urban centres, tax burdens) peasant uprisings became more frequent (such as the Shimabara Uprising). While not necessarily the fault of Christian beliefs, the fact that Christian peasants were challenging their daimyo nevertheless equated Western influence with challenge to authority (Laver, The Sakoku Edicts).
So the shoguns certainly had many reasons to at least try Sakoku, but the question of whether it achieved its aims can be answered simply by looking at the fate of the shoguns. Stifling the intellectual development of the samurai, choking the wealth of the daimyo and ignoring potential external threats had the effect of galvanising Japan's elite (or at least a powerful section of it) to challenge the shogun and institute a new oligarchy in the Meiji Restoration. Its internal aims also failed to come to fruition with increasing peasant uprisings and dissent amongst Japan's growing and changing urban population. Nevertheless, for a substantial period Japan was able to protect complete depletion of its natural resources by the European powers. While the Sakoku period was certainly devastating to the shoguns in the long term, it was not entirely meritless. It followed a certain logic that, while it may not have benefited Japan as a whole, certainly had some sectional interests at its heart.