In the Star Trek: The Next Generation episode, Q-Who, Q decides to expose the Enterprise to one of the unknown threats that lies out there in the galaxy. He hurls the Enterprise to the distant System J-25, where they encounter the Borg, who promptly show their technological superiority. What were Q's motives for exposing the Enterprise to this threat?
An excerpt from the Memory Alpha summary for the episode "Q Who" states the following:
(As the Enterprise is losing to the Borg ship...) Q demands whether they still believe to be prepared, to which Picard admits that they are frightened and that Q has shown them to be inadequate. Picard asks Q's help, saying that they need him, to which, with a snap of his fingers, Q flings the Enterprise back into Federation space. He congratulates Picard for admitting his need for help, claiming that "another man would have been humiliated to say those words." Picard is still upset about the loss of eighteen of his crew, but Q is unapologetic, telling him that the universe is not a safe place before disappearing. The Enterprise sets course for the nearest starbase.
Reflecting upon events in Ten Forward with Picard, Guinan says that the encounter with the Borg happened before it should have, and for the moment, the Borg are only capable of seeing the Federation as "raw material to them". And because they are now, Guinan begins, "aware of our existence," "they will be coming," Picard continues. Guinan ominously says, "You can bet on it." Picard comments that perhaps Q did the right thing for the wrong reasons, to shake humanity out of its complacency for whatever lies ahead.
So, it would seem that Q's motive is to prove the point that the Federation is unprepared for and unsuspecting of what dangers lie ahead of them as they explore further into the universe. While Q may have done this for his own personal amusement or to stroke his own ego, it did still end up helping the Federation by cluing them in to the existence of the Borg, as noted under the Trivia section:
It's later revealed that due to the events shown in Star Trek: First Contact and "Regeneration" the Borg already knew of Earth's existence and were on their way. This means Q's actions were an early warning for the Federation.
However, whether or not Q specifically intended to help them in this way isn't altogether certain.
It was to show what lies ahead. Picard said: "Maybe Q did the right thing for the wrong reason". I guess it was to show that the federation is not prepared what lies ahead and that they are vulnerable.
The Borg were already aware of the earth as they had already assimilated 7 of 9's family previously!