Why do we suddenly forget things, like PIN or phone numbers, that we've known for years?
Forgetfulness is a common phenomenon that tends to increase with age. It usually affects short term memories but it can affect long term ones too. Here are some possible causes which I quote from Healthline (the full list available at that link):


  
  sleep deprivation
  use of alcohol or drugs and some prescription medications
  lack of oxygen to the brain
  migraine
  


It can happen at any age and it is normal if (quoting Deane Alban, Memory Loss: When It’s Normal and When It’s Serious):


  Are you overworked and stressed out? Are you eating poorly? Are you on a low-fat diet or skipping meals to lose weight?  Do you struggle with insomnia? Do you drink too much?
  
  If you answer “yes” to any of these questions, it’s likely you are losing your memory because your lifestyle is catching up with you. 


You mention loss during sleep in your question. Sleep affects memories (see WebMD and Wikipedia):


deprivation of sleep leads to memory loss
during sleep brain selects relevant information gathered during the day and turns it into memories
certain stages of sleep improve memories