The episodes of dizziness you describe sound like vertigo.
Like you, people with vertigo experience a sensation that the room is spinning. Or they may feel that they are spinning in the room. Sometimes it is just a sense of imbalance. Vertigo may be associated with nausea, vomiting, and ringing in one or both ears (tinnitus).
Melatonin is considered to be a relatively safe supplement for short-term use. There are reports of balance and equilibrium problems at higher doses, usually more than 5 milligrams per day. So its not likely that the melatonin is causing the vertigo. The only way to know for sure is to stop taking it.
When a person has recurrent episodes of vertigo, I usually suspect a disorder called benign position vertigo (BPV). In this condition, small crystals break loose in the canals of the inner ear and touch the sensitive nerve endings inside. A change in head position sets this off, causing sudden episodes of a spinning sensation.
Another potential cause of vertigo is Mιniθres disease. But people with Mιniθres dont usually have symptoms that recur so often. Also, the vertigo of Mιniθres is accompanied by ringing in the ear and some hearing loss.
A much rarer cause of recurrent vertigo is intermittent interruption of blood flow to the back part of the brain.
Your next step should be to talk with your doctor about your symptoms. If this is benign positional vertigo, your doctor may advise Epley maneuvers. This involves moving the head in a sequence of positions that directs the floating crystals into a part of the inner ear with fewer nerve endings.