Oscar Wilde's "The Nightingale and the Rose" is a short story that illustrates the philosophy of true love in the form of the nightingale.
The nightingale is the symbol of all the things that should be in place for love to be eternal: The will to sacrifice, the acceptance of failure, even the willingness to let go just for the sake of maintaining the capacity of love in your heart.
In contrast, the story also shows how isolated that philosophy of eternal and true love is from the reality of life: Not everyone believes in true and eternal love. Some people are quite happy living superficial lives and experimenting for the moment.
That is what the student is: Simply capricious about the girl for whom he wants the red rose. He does not believe in passion, nor sacrifice; he only believes in his instant gratification. Therefore, it is no surprise that he takes the sacrifice of the nightingale for granted, and ignores completely the magnitude of what the nightingale did for him.
In conclusion, the nightingale does what she feels it the correct thing to do in order to maintain the idea of pure, eternal, and true love alive. She does not die for the student, nor for the girl; she dies for the ideal that she embodies, and in order to maintain that ideal alive in the minds of those who witnessed the moment of her death.