It might be because of a forgotten sinful act which needs seeking forgiveness (Istighfaar) or it can be because Najis bed or Najis sheet etc. It can be also because of late meal which causes bad dreams.
It is mentioned in many Hadeeths that i is recommended to go to toilet before going to bed.
Wassalam.