Apple computers change their sleep and wake behavior depending on the power source the computer is using. The sources are Battery and Power Adapter, and they can be configured independently through: System Preferences / Battery.
For more in-depth information follow the links below: