The Giver uses the sun to transmit to Jonas the experiences of pleasure and pain. In the Giver's society emotion is not known. The population lives in a complete utopia of sorts where there is no pain, hate, bigotry, war, famine, etc. There also isn't any love or joy. Memories of those bad things have also been eradicated from the general population. The memories cannot be completely removed though, which is why a "receiver of memory" exists. Jonas is the new receiver.
As part of his early training the Giver gives Jonas the memory and sensation of sunshine. Jonas understands it and experiences it as pleasure. Jonas then asked the Giver about the pain he was to learn and experience. The Giver decided to start with something mild, so he allowed Jonas to experience sunburn. Jonas perceived that as pain, even though it was likely more akin to discomfort rather than actual pain.