There were at least three main reasons for the closing of Japan during the Tokugawa Shogunate. They include:
Desire to keep Japan from being colonize. The shoguns did not want the Portuguese and Spanish to gain control of their country.
Desire to keep Christianity out. During the time that Japan allowed foreign contact, Christianity started to spread in the country. This caused problems for the shogunate as converts became less content with the existing order.
Economic reasons. The shogunate did not want to simply close Japan. They wanted to maintain trade so long as that trade was tightly controlled. In that way, only the shogunate (rather than individual daimyo) would gain from trading with the outside world.