Why, in the time of Samuel the prophet, did the twelve tribes feel they needed a king over them?

...the king's job was to raise the flag of Torah...

Shem miShmuel answers that the task of the judges was to secure the land of Israel for the Jews (since for several generations after they entered the Promised Land, the Canaanites were still present). The task of a king, though, was over and beyond securing the land; the king's job was to raise the flag of Torah and spread its message throughout the world.

In short, the job of a judge was to govern, while that of a king was not only to govern, but more importantly, to spread G‑dliness and elevate the world.

Joseph's dream of the sheaves implied to the brothers that Joseph would govern like a judge over a limited territory for a limited period of time, and be answerable to someone above him. This was entirely acceptable to them.

But, when they heard the second dream, in which the sun and the moon (indicating their mother and father) were also bowing down to Joseph, the brothers concluded that Joseph intended to take on the kingship as well. That is, they reasoned, he doesn't intend to rule as a judge for the purpose of protection of his subjects, but as a king, for the purpose of spreading G‑dliness and spirituality beyond his own boundaries. This, they concluded, was treason, because the King of the Jews was to come from another brother – Judah – not from Joseph.

...the King of the Jews was to come from another brother – Judah – not from Joseph.

Therefore, they were determined to prevent him from becoming a king. They sold him into slavery, in order to insure that even if he ruled under Pharaoh as a judge, he would never rule as a king.

What the brothers didn't know was that Joseph had the power of both a judge (to protect) and also a king (to spread holiness beyond his own boundaries). We see this clearly in Egypt; not only did Joseph withstand the temptations of his master's wife and other women in Egypt (indicating his ability to protect his own borders), but he ultimately expanded the borders of holiness to include some of the Egyptians themselves.

~~~~~~~~~~~~~~~~~~

[From "Inner Lights from Jerusalem" based on Shem miShmuel and other Chassidic and Kabalistic Sources, translated and presented by Rabbi David Sterne.]