Why wouldn't it be safe?? Do you know they even make relaxation music cd's and tapes to help promote winding down and relaxing before sleep? If listening to music helps, do it! My parents use to let us listen to to tapes when we were little to put us to sleep and keep us in bed.
Yes it is safe as most of the students now a days do this while they go to sleep. But one such incident happen in NAGPUR in INDIA. a boy who went to sleep with mobile's ear phone in his ears and the charger was ON, in the early hours of the morning the battery got burst and he got hurt severely. No doubt he is live but marks on his face are left for ever.
I have heard that it can hurt your ears and damage them if the music is too loud. And I have heard that there's like a ton of bacteria or something the longer you keep the head phones on or something ....idk . Just don't listen to it loud