How do pilots get enough sleep in preparation for a long night flight?
Short answer: Sleep aids cannot be used this way in the US. FAA regulates the use of such medications with a delay:


Pharmaceuticals (Therapeutic Medications) Sleep Aids:  

More on medication advice to medical examiners: Pharmaceuticals (Therapeutic Medications) - Do Not Issue - Do Not Fly.


Only the zaleplon molecule (a Z-drug ⁞ hypnotic) could be used in a practical manner (not publicly available in France nor likely in many other countries).




Circadian rhythm

What you are referring to has got the scientific name of circadian rhythm (circa = around, diēs = day), which is the subject of an article at SkyBrary: Circadian Rhythms. About the night flights:


  Night operations create a host of problems for flight crews. The
  primary problem is having to work efficiently and safely at a point in
  time when the work requirements are not in synchrony with circadian
  rhythms. Under worst-case conditions, crew members must perform
  demanding tasks during the early morning hours (2 am to 6 am) when
  their biological functions and performance efficiency are at their
  lowest level. This problem cannot be quickly solved by adaptation of
  the biological clock. Complete adjustment to night work requires at
  least 21 night shifts in a row with no days off. Adjustment of the
  biological clock does not even commence until about 10 days after a
  shift change.



Fatigue

Long article about Fatigue Countermeasures in Aviation, about zaleplon:


  This misalignment of the sleep/wake cycle and endogenous circadian
  rhythms could be the result of shift lag, jet lag, or attempting
  sleep at other than the habitual bedtime or at the second circadian
  dip in the afternoon. For such circumstances, the U.S. Air Force and
  Army have approved the limited use of temazepam, zolpidem, and
  zaleplon. These hypnotics can optimize the quality of crew
  rest in circumstances where sleep is possible, but difficult to
  obtain.



Inflight rest

As additional information about sleep management inflight: On a 8-hour flight, usually there will be 3 pilots, and each one will be able to sleep (outside the flight deck).


Air France Inflight rest for crews.
Air Canada When do pilots get to rest during long haul flights?
What Do Cabin Crews' Chillaxation Spots Look Like?