If you mean Hideyoshi's orders which kind of extended to the early Edo, the reason is for social organization and, for Hideyoshi who wanted to invade Korea, military mobilization.
However, the order slowly broke down and by mid and late Edo period samurai took other jobs. Most encouraged were bureaucrats and teachers, but many poorer samurai returned to farming to make ends meet.