Death is a wrong word to be associated with Avatars of Vishnu . Their sole purpose is to establish Dharma and once it is restored they return to their heavenly abode or Vaikuntha . But story behind these events is always interesting.
According to Hindu mythology there’s a story behind Lord Rama’s death which is depicted here below:
Ram’s reign lasted for 11000 years and was marked with prosperity, complete peace and harmony. One day, a sage came to Sri Ram and asked for a private audience and said that if someone enters the room, he will be put to death. It is believed that the old sage was KALA or Time himself. So while their conversation Sage Durvasa, famous for his short tempered nature, arrived outside the room and asked Laskhmana for a meeting with Lord Rama. Lakshmana , who was guarding the room , promptly denied . This enraged Sage Durvasa and he threatened that he will lay a terrible curse of destruction on entire Raghu clan. Lakshmana was completely perplexed, but after some time he concluded that his death would be better than the disastrous curse on whole Ayodhya. He realized that it is just play of time and time has come to leave this materialistic world. He then submerged himself into Saryu river and disappeared and took the form of SheshaNaga . When Rama came to know about the death of Lakshmana, he decided to end his avatar and soon walked deep into Saryu river and after sometime Vishnu appeared resting on SheshNaga.
Also, it is believed that as Lakshmana is incarnation of SheshaNaga on whom Lord Vishnu rests, it was essential for Lakshmana to die before Rama so that when Rama gives up his life and returns to Vaikuntha as Vishnu, his seat is already ready.