Ibn ul-Qayyim رحمه الله said:
“I consider that a man forgets (some) knowledge he used to know, due to a sin he commits”.
Al-Fawā’id p.215
Translation: Abu Muadh Taqweem (حفظه الله)