It is narrated from Hazrat Aisha (may Allah be pleased with her) that the Prophet (peace and blessings be upon him) would sometimes perform ghusl before sleeping and sometimes sleep before performing ghusl. Similarly, the Prophet (peace and blessings be upon him) would sometimes offer witr before sleeping and sometimes after sleeping.