In Act I, Scene 2, Ariel uses his magical powers to put Gonzalo, Alonso, and other members of the ship's crew to sleep. This allows Prospero and Miranda to approach the ship undetected and discuss their plan to seek revenge against those who wronged them.
Later in the play, Prospero also puts Caliban and his companions to sleep in order to prevent them from interfering with his plans.
Thus, the characters are put to sleep to serve as a plot device that allows the main characters to execute their plans without facing any resistance or opposition.